migrations needs order fix, fixing to save

This commit is contained in:
filipriec
2025-03-01 16:20:18 +01:00
parent 00f0889bed
commit b31242e63b
2 changed files with 21 additions and 3 deletions

View File

@@ -2,11 +2,20 @@
CREATE TABLE table_definitions (
id BIGSERIAL PRIMARY KEY,
deleted BOOLEAN NOT NULL DEFAULT FALSE,
firma TEXT NOT NULL,
table_name TEXT NOT NULL UNIQUE,
columns JSONB NOT NULL,
indexes JSONB NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
profile_id BIGINT NOT NULL REFERENCES profiles(id) DEFAULT 1,
linked_table_id BIGINT REFERENCES table_definitions(id)
);
CREATE INDEX idx_table_definitions_table_name ON table_definitions (table_name);
-- Create composite unique index for profile+table combination
CREATE UNIQUE INDEX idx_table_definitions_profile_table
ON table_definitions (profile_id, table_name);
-- Add self-referential foreign key constraint
ALTER TABLE table_definitions
ADD CONSTRAINT fk_linked_table
FOREIGN KEY (linked_table_id)
REFERENCES table_definitions(id);

View File

@@ -0,0 +1,9 @@
-- Add migration script here
CREATE TABLE profiles (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
-- Create default profile for existing data
INSERT INTO profiles (name) VALUES ('default');