Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
document the correct way to create a new enum value
  • Loading branch information
coadler committed Dec 1, 2023
commit 3ca5ebf4155d4e8d96404f3863fc17e55aeb5abe
17 changes: 17 additions & 0 deletions coderd/database/migrations/create_migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ enum value needs to be referenced in another migration.
This also means you should not use "BEGIN;" and "COMMIT;" in your migrations, as
everything is already in a migration.

An example way of the proper way to add an enum value:

CREATE TYPE new_logintype AS ENUM (
'password',
'github',
'oidc',
'token' -- this is our new value
);

ALTER TABLE users
ALTER COLUMN login_type DROP DEFAULT, -- if the column has a default, it must be dropped first
ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype), -- converts the old enum until the new enum using text as an intermediary
ALTER COLUMN login_type SET DEFAULT 'password'::new_logintype; -- re-add the default using the new enum

DROP TYPE login_type;
ALTER TYPE new_logintype RENAME TO login_type;

EOF

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
Expand Down