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
This commit is contained in:
@@ -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
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user