quivr/scripts/20231205163000_new_table_composite_brain_connections.sql
Zineb El Bachiri 5bbc72eb09
feat: composite brains db (#1826)
# Description

- db for composite brains & repository
- composite brains creation
2023-12-06 08:40:18 +01:00

33 lines
955 B
SQL

DO $$
BEGIN
-- Check if 'composite' already exists in the enum
IF NOT EXISTS (
SELECT 1 FROM pg_enum
WHERE enumlabel = 'composite'
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'brain_type_enum')
) THEN
-- Add 'composite' to the enum
ALTER TYPE brain_type_enum ADD VALUE 'composite';
END IF;
-- Table for storing the relationship between brains for composite brains
CREATE TABLE IF NOT EXISTS composite_brain_connections (
composite_brain_id UUID NOT NULL REFERENCES brains(brain_id),
connected_brain_id UUID NOT NULL REFERENCES brains(brain_id),
PRIMARY KEY (composite_brain_id, connected_brain_id),
CHECK (composite_brain_id != connected_brain_id)
);
END $$;
-- Update migrations table
INSERT INTO migrations (name)
SELECT '20231205163000_new_table_composite_brain_connections'
WHERE NOT EXISTS (
SELECT 1 FROM migrations WHERE name = '20231205163000_new_table_composite_brain_connections'
);
COMMIT;