-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add not null constraint on files.type
- Loading branch information
Showing
3 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
apps/backend/db/migrations/20231115210334_file-type-not-null.js
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,31 @@ | ||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
export const up = async (knex) => { | ||
await knex.raw(` | ||
ALTER TABLE files ADD CONSTRAINT files_type_not_null_constraint CHECK (type IS NOT NULL) NOT VALID; | ||
`); | ||
|
||
await knex.raw(` | ||
ALTER TABLE files VALIDATE CONSTRAINT files_type_not_null_constraint; | ||
`); | ||
|
||
await knex.raw(` | ||
ALTER TABLE files ALTER column type SET NOT NULL; | ||
`); | ||
|
||
await knex.raw(` | ||
ALTER TABLE files DROP CONSTRAINT files_type_not_null_constraint; | ||
`); | ||
}; | ||
|
||
/** | ||
* @param {import('knex').Knex} knex | ||
*/ | ||
export const down = async (knex) => { | ||
await knex.raw(` | ||
ALTER TABLE files ALTER column type DROP NOT NULL; | ||
`); | ||
}; | ||
|
||
export const config = { transaction: false }; |
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
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