process raw_store_events records automatically via triggers
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
DROP TABLE tiktok_store_events;
|
DROP TABLE tiktok_store_events;
|
||||||
DROP TABLE etsy_store_events;
|
DROP TABLE etsy_store_events;
|
||||||
DROP TABLE wix_store_events;
|
DROP TABLE wix_store_events;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
CREATE TABLE tiktok_store_events (
|
CREATE TABLE tiktok_store_events (
|
||||||
platform TEXT NOT NULL DEFAULT 'tiktok' CHECK (platform = 'tiktok'),
|
platform TEXT NOT NULL DEFAULT 'tiktok' CHECK (platform = 'tiktok'),
|
||||||
store_id TEXT NOT NULL,
|
store_id TEXT NOT NULL,
|
||||||
@@ -27,3 +29,5 @@ CREATE TABLE wix_store_events (
|
|||||||
PRIMARY KEY (store_id, event_id, event_timestamp),
|
PRIMARY KEY (store_id, event_id, event_timestamp),
|
||||||
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES raw_store_events
|
FOREIGN KEY (platform, store_id, event_id, event_timestamp) REFERENCES raw_store_events
|
||||||
);
|
);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
DROP TRIGGER tiktok_store_events;
|
||||||
|
|
||||||
|
DROP FUNCTION process_raw_tiktok_event;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION process_raw_tiktok_event() RETURNS TRIGGER AS $process_raw_tiktok_event$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO tiktok_store_events (
|
||||||
|
platform,
|
||||||
|
store_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
NEW.platform,
|
||||||
|
NEW.store_id,
|
||||||
|
NEW.event_timestamp,
|
||||||
|
NEW.event_id;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$process_raw_tiktok_event$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER tiktok_store_events
|
||||||
|
AFTER INSERT ON raw_store_events
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (NEW.platform = 'tiktok')
|
||||||
|
EXECUTE FUNCTION process_raw_tiktok_event();
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE raw_store_events DROP COLUMN IF EXISTS parsed;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
DROP TRIGGER etsy_store_events;
|
||||||
|
|
||||||
|
DROP FUNCTION process_raw_etsy_event;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION process_raw_etsy_event() RETURNS TRIGGER AS $process_raw_etsy_event$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO etsy_store_events (
|
||||||
|
platform,
|
||||||
|
store_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
NEW.platform,
|
||||||
|
NEW.store_id,
|
||||||
|
NEW.event_timestamp,
|
||||||
|
NEW.event_id;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$process_raw_etsy_event$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER etsy_store_events
|
||||||
|
AFTER INSERT ON raw_store_events
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (NEW.platform = 'etsy')
|
||||||
|
EXECUTE FUNCTION process_raw_etsy_event();
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
DROP TRIGGER wix_store_events;
|
||||||
|
|
||||||
|
DROP FUNCTION process_raw_wix_event;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION process_raw_wix_event() RETURNS TRIGGER AS $process_raw_wix_event$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO wix_store_events (
|
||||||
|
platform,
|
||||||
|
store_id,
|
||||||
|
event_timestamp,
|
||||||
|
event_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
NEW.platform,
|
||||||
|
NEW.store_id,
|
||||||
|
NEW.event_timestamp,
|
||||||
|
NEW.event_id;
|
||||||
|
RETURN NULL;
|
||||||
|
END;
|
||||||
|
$process_raw_wix_event$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER wix_store_events
|
||||||
|
AFTER INSERT ON raw_store_events
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (NEW.platform = 'wix')
|
||||||
|
EXECUTE FUNCTION process_raw_wix_event();
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user