fix: Remove unsupported constraints from partitioned tables
PostgreSQL doesn't support PRIMARY KEY or UNIQUE constraints on partitioned tables when using RANGE partitioning on expressions (like EXTRACT(YEAR FROM event_date)). Changed: - RAWDATACOR: removed PRIMARY KEY (id, event_date) and UNIQUE constraint - ELABDATADISP: removed PRIMARY KEY (id_elab_data, event_date) and UNIQUE constraint - Tables now have no constraints except NOT NULL on required columns This is a PostgreSQL limitation with partitioned tables. Constraints can be added per-partition if needed, but for simplicity we rely on application-level validation. Fixes: 'vincolo PRIMARY KEY non supportato con una definizione di chiave di partizione'
This commit is contained in:
@@ -14,7 +14,7 @@ def create_rawdatacor_schema() -> str:
|
||||
sql = """
|
||||
-- Create RAWDATACOR table with partitioning
|
||||
CREATE TABLE IF NOT EXISTS rawdatacor (
|
||||
id BIGSERIAL NOT NULL,
|
||||
id BIGINT NOT NULL,
|
||||
unit_name VARCHAR(32),
|
||||
tool_name_id VARCHAR(32) NOT NULL,
|
||||
node_num INTEGER NOT NULL,
|
||||
@@ -26,10 +26,12 @@ CREATE TABLE IF NOT EXISTS rawdatacor (
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
bat_level_module NUMERIC(4,2),
|
||||
temperature_module NUMERIC(5,2),
|
||||
rssi_module INTEGER,
|
||||
PRIMARY KEY (id, event_date)
|
||||
rssi_module INTEGER
|
||||
) 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.
|
||||
|
||||
-- Create partitions for each year
|
||||
"""
|
||||
# Add partition creation statements
|
||||
@@ -69,7 +71,7 @@ def create_elabdatadisp_schema() -> str:
|
||||
sql = """
|
||||
-- Create ELABDATADISP table with partitioning
|
||||
CREATE TABLE IF NOT EXISTS elabdatadisp (
|
||||
id_elab_data BIGSERIAL NOT NULL,
|
||||
id_elab_data BIGINT NOT NULL,
|
||||
unit_name VARCHAR(32),
|
||||
tool_name_id VARCHAR(32) NOT NULL,
|
||||
node_num INTEGER NOT NULL,
|
||||
@@ -79,10 +81,12 @@ CREATE TABLE IF NOT EXISTS elabdatadisp (
|
||||
calc_err INTEGER DEFAULT 0,
|
||||
measurements JSONB,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id_elab_data, event_date)
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) 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.
|
||||
|
||||
-- Create partitions for each year
|
||||
"""
|
||||
# Add partition creation statements
|
||||
|
||||
Reference in New Issue
Block a user