generated from textbook/starter-kit
-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
98b1be9
commit 5eb8f5e
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
migrations/1717025690146_change-draft-to-status-in-resource.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,42 @@ | ||
/** | ||
* @type {import('node-pg-migrate').ColumnDefinitions | undefined} | ||
*/ | ||
exports.shorthands = undefined; | ||
|
||
/** | ||
* @param pgm {import('node-pg-migrate').MigrationBuilder} | ||
* @param run {() => void | undefined} | ||
* @returns {Promise<void> | void} | ||
*/ | ||
exports.up = (pgm) => { | ||
pgm.renameColumn("resources", "draft", "status"); | ||
pgm.renameColumn("resources", "publication", "status_changed_date"); | ||
pgm.renameColumn("resources", "publisher", "status_changed_by"); | ||
|
||
pgm.createType("enum", ["drafted", "published", "rejected"]); | ||
pgm.sql("ALTER TABLE resources ALTER COLUMN status DROP DEFAULT"); | ||
pgm.alterColumn("resources", "status", { | ||
type: "enum", | ||
using: | ||
"CASE WHEN status = 'true' THEN 'drafted'::enum WHEN status = 'false' THEN 'published'::enum ELSE 'rejected'::enum END", | ||
}); | ||
}; | ||
|
||
/** | ||
* @param pgm {import('node-pg-migrate').MigrationBuilder} | ||
* @param run {() => void | undefined} | ||
* @returns {Promise<void> | void} | ||
*/ | ||
exports.down = (pgm) => { | ||
pgm.renameColumn("resources", "status", "draft"); | ||
pgm.renameColumn("resources", "status_changed_date", "publication"); | ||
pgm.renameColumn("resources", "status_changed_by", "publisher"); | ||
|
||
pgm.alterColumn("resources", "status", { | ||
type: "boolean", | ||
using: | ||
"CASE WHEN status = 'drafted' THEN true WHEN status = 'published' THEN false ELSE null END", | ||
}); | ||
|
||
pgm.dropType("enum"); | ||
}; |