diff --git a/src/transformers/schema_transformer.py b/src/transformers/schema_transformer.py index 12c0047..25dc4d4 100644 --- a/src/transformers/schema_transformer.py +++ b/src/transformers/schema_transformer.py @@ -12,9 +12,12 @@ def create_rawdatacor_schema() -> str: SQL script to create the table with partitions """ sql = """ +-- Create sequence for id auto-increment +CREATE SEQUENCE IF NOT EXISTS rawdatacor_id_seq; + -- Create RAWDATACOR table with partitioning CREATE TABLE IF NOT EXISTS rawdatacor ( - id BIGINT NOT NULL, + id BIGINT NOT NULL DEFAULT nextval('rawdatacor_id_seq'), unit_name VARCHAR(32), tool_name_id VARCHAR(32) NOT NULL, node_num INTEGER NOT NULL, @@ -30,7 +33,7 @@ CREATE TABLE IF NOT EXISTS rawdatacor ( ) PARTITION BY RANGE (EXTRACT(YEAR FROM event_date)); -- Note: PostgreSQL doesn't support PRIMARY KEY or UNIQUE constraints --- with RANGE partitioning on expressions. Constraints are added on partitions. +-- with RANGE partitioning on expressions. Using sequence for id auto-increment. -- Create partitions for each year """ @@ -69,9 +72,12 @@ def create_elabdatadisp_schema() -> str: SQL script to create the table with partitions """ sql = """ +-- Create sequence for id_elab_data auto-increment +CREATE SEQUENCE IF NOT EXISTS elabdatadisp_id_seq; + -- Create ELABDATADISP table with partitioning CREATE TABLE IF NOT EXISTS elabdatadisp ( - id_elab_data BIGINT NOT NULL, + id_elab_data BIGINT NOT NULL DEFAULT nextval('elabdatadisp_id_seq'), unit_name VARCHAR(32), tool_name_id VARCHAR(32) NOT NULL, node_num INTEGER NOT NULL, @@ -85,7 +91,7 @@ CREATE TABLE IF NOT EXISTS elabdatadisp ( ) PARTITION BY RANGE (EXTRACT(YEAR FROM event_date)); -- Note: PostgreSQL doesn't support PRIMARY KEY or UNIQUE constraints --- with RANGE partitioning on expressions. Constraints are added on partitions. +-- with RANGE partitioning on expressions. Using sequence for id_elab_data auto-increment. -- Create partitions for each year """