Compare commits

...

3 Commits

Author SHA1 Message Date
10d5bdc518 Removed the dumb extension stuf 2025-11-12 21:40:35 +00:00
5ecf58ba6a Once again missed something 2025-11-12 21:37:45 +00:00
5002528eae More views and no longer dropping schema 2025-11-12 21:36:00 +00:00

View File

@@ -2,11 +2,11 @@
-- Cleanup schema public first. -- Cleanup schema public first.
DROP SCHEMA IF EXISTS public CASCADE; ---DROP SCHEMA IF EXISTS public CASCADE;
-- Recreate schema public. -- Recreate schema public.
CREATE SCHEMA public; CREATE SCHEMA public if not exists;
-- Set ownership to meta_user -- Set ownership to meta_user
ALTER SCHEMA public OWNER TO meta_user; ALTER SCHEMA public OWNER TO meta_user;
@@ -17,7 +17,7 @@ ALTER SCHEMA public OWNER TO meta_user;
-- Create TimescaleDB extension if it doesn't exist -- Create TimescaleDB extension if it doesn't exist
-- This provides time_bucket() and other time-series functions -- This provides time_bucket() and other time-series functions
CREATE EXTENSION IF NOT EXISTS timescaledb; --CREATE EXTENSION IF NOT EXISTS timescaledb;
-- ============================================================================ -- ============================================================================
-- METADATA TABLE -- METADATA TABLE
@@ -25,6 +25,7 @@ CREATE EXTENSION IF NOT EXISTS timescaledb;
-- This table stores account mappings and identifiers -- This table stores account mappings and identifiers
-- Data is loaded from metadata.yaml file -- Data is loaded from metadata.yaml file
CREATE TABLE IF NOT EXISTS public.account_metadata ( CREATE TABLE IF NOT EXISTS public.account_metadata (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
label VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL,
@@ -342,6 +343,9 @@ SELECT
(SELECT SUM((elem.value ->> 'value')::numeric) (SELECT SUM((elem.value ->> 'value')::numeric)
FROM jsonb_array_elements(ins.actions) AS elem FROM jsonb_array_elements(ins.actions) AS elem
WHERE (elem.value ->> 'action_type') = 'lead') AS lead, WHERE (elem.value ->> 'action_type') = 'lead') AS lead,
(SELECT sum((value->>'value')::numeric)
FROM jsonb_array_elements(actions)
WHERE value->>'action_type' = 'landing_page_view') AS landing_page_view,
spend, spend,
frequency, frequency,
cpc, cpc,
@@ -382,7 +386,7 @@ SELECT
avg(ctr) as ctr avg(ctr) as ctr
FROM ads_insights FROM ads_insights
group by time, account_id, adset_id, campaign_id group by time, account_id, adset_id, campaign_id;
DROP VIEW IF EXISTS g_account_insights CASCADE; DROP VIEW IF EXISTS g_account_insights CASCADE;