generated from textbook/starter-kit
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing constraints to users table
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
/** | ||
* Defines changes to be made to the database schema to accommodate new functionality. | ||
* | ||
* See {@link https://salsita.github.io/node-pg-migrate/#/migrations?id=defining-migrations the docs}. | ||
* | ||
* @param {MigrationBuilder} pgm | ||
* @returns {void | Promise<void>} | ||
*/ | ||
exports.up = (pgm) => { | ||
pgm.alterColumn("users", "name", { notNull: true }); | ||
pgm.alterColumn("users", "github_id", { notNull: true }); | ||
pgm.addConstraint("users", "unique_github_ids", { unique: ["github_id"] }); | ||
}; | ||
|
||
/** | ||
* Reverses the "up" migration to return the database to its initial state. | ||
* | ||
* @param {MigrationBuilder} pgm | ||
* @returns {void | Promise<void>} | ||
*/ | ||
exports.down = (pgm) => { | ||
pgm.dropConstraint("users", "unique_github_ids"); | ||
pgm.alterColumn("users", "github_id", { notNull: false }); | ||
pgm.alterColumn("users", "name", { notNull: false }); | ||
}; | ||
|
||
/** | ||
* Create new shorthand column definitions for this and any future migrations. | ||
* | ||
* @type {ColumnDefinitions | undefined} | ||
*/ | ||
exports.shorthands = undefined; | ||
|
||
/** | ||
* Importing library types for less verbose type hints. | ||
* @typedef {import("node-pg-migrate").MigrationBuilder} MigrationBuilder | ||
* @typedef {import("node-pg-migrate").ColumnDefinitions} ColumnDefinitions | ||
*/ |