diff --git a/server/migrations/20250301093450_create_table_definitions.sql b/server/migrations/20250301093450_create_table_definitions.sql index f75837f..591718e 100644 --- a/server/migrations/20250301093450_create_table_definitions.sql +++ b/server/migrations/20250301093450_create_table_definitions.sql @@ -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); diff --git a/server/migrations/20250301142238_create_profiles.sql b/server/migrations/20250301142238_create_profiles.sql new file mode 100644 index 0000000..ba2c9d4 --- /dev/null +++ b/server/migrations/20250301142238_create_profiles.sql @@ -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');