-- Add migration script here
CREATE TABLE table_scripts (
    id BIGSERIAL PRIMARY KEY,
    table_definitions_id BIGINT NOT NULL REFERENCES table_definitions(id),
    target_table TEXT NOT NULL,
    target_column TEXT NOT NULL,
    target_column_type TEXT NOT NULL,
    script TEXT NOT NULL,
    description TEXT,
    created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    schema_id BIGINT NOT NULL REFERENCES schemas(id),
    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);
