-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5feaecf
commit 844ec0f
Showing
3 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
scripts/20231106110000_add_field_brain_type_to_brain_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- Check if the ENUM type 'brain_type' already exists | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'brain_type_enum') THEN | ||
-- Create the ENUM type 'brain_type' if it doesn't exist | ||
CREATE TYPE brain_type_enum AS ENUM ('doc', 'api'); | ||
END IF; | ||
END $$; | ||
|
||
-- Add a column 'brain_type' to the 'brains' table using the 'brain_type' ENUM type | ||
BEGIN; | ||
|
||
-- Add a column 'brain_type' to the 'brains' table as the 'brain_type' ENUM type with a default value 'doc' | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'brains' | ||
AND column_name = 'brain_type' | ||
) THEN | ||
ALTER TABLE brains ADD COLUMN brain_type brain_type_enum DEFAULT 'doc'; | ||
END IF; | ||
END $$; | ||
|
||
-- Insert a migration record if it doesn't exist | ||
INSERT INTO migrations (name) | ||
SELECT '20231106110000_add_field_brain_type_to_brain_table' | ||
WHERE NOT EXISTS ( | ||
SELECT 1 FROM migrations WHERE name = '20231106110000_add_field_brain_type_to_brain_table' | ||
); | ||
|
||
-- Commit the changes | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters