Files
komp_ac/server/migrations/20250306132638_create_table_scripts.sql
2025-03-07 10:45:35 +01:00

19 lines
791 B
SQL

-- Add migration script here
CREATE TABLE table_scripts (
id BIGSERIAL PRIMARY KEY,
table_definitions_id BIGINT NOT NULL REFERENCES table_definitions(id),
target_column TEXT NOT NULL,
script TEXT NOT NULL,
source_tables TEXT[] NOT NULL, -- Added to track which tables are used in calculation
source_columns TEXT[] NOT NULL, -- Added to track which columns are used in calculation
description TEXT, -- Optional description of what the script does
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(table_definitions_id, target_column)
);
-- Add foreign key constraint
ALTER TABLE table_scripts
ADD CONSTRAINT fk_table_definition
FOREIGN KEY (table_definitions_id)
REFERENCES table_definitions(id);