-- 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,
    rhai_script TEXT NOT NULL,
    compiled_script BYTEA NOT NULL,
    created_at TIMESTAMPTZ 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);
