From de6bde17c990b32c72f252173073e6f09f2c208c Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 10 Dec 2025 20:20:52 +0100 Subject: [PATCH] feat: Add sequences for auto-incrementing IDs - Create rawdatacor_id_seq for auto-increment of id column - Create elabdatadisp_id_seq for auto-increment of id_elab_data column - Both sequences use DEFAULT nextval() to auto-generate IDs on insert This replaces PRIMARY KEY functionality since PostgreSQL doesn't support PRIMARY KEY on partitioned tables with expression-based ranges. IDs are now auto-incremented without primary key constraint. Tested: schema creation works correctly with sequences --- src/transformers/schema_transformer.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 """