-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/database/src/migrations/20240813211928-AddParentTaskColumn-modifies-schema.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,45 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function (options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = async function (db) { | ||
await db.addColumn('task', 'parent_task_id', { | ||
type: 'text', | ||
foreignKey: { | ||
name: 'task_parent_task_id_fk', | ||
table: 'task', | ||
mapping: 'id', | ||
// Don't cascade delete, as we want to keep the task even if the parent task is deleted, just set as null | ||
rules: { | ||
onDelete: 'SET NULL', | ||
onUpdate: 'CASCADE', | ||
}, | ||
}, | ||
ifNotExists: true, | ||
}); | ||
return db.runSql(` | ||
CREATE INDEX IF NOT EXISTS task_parent_task_id_fk ON task USING btree (parent_task_id); | ||
`); | ||
}; | ||
|
||
exports.down = function (db) { | ||
return db.removeColumn('task', 'parent_task_id', { | ||
ifExists: true, | ||
}); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.