Last active
October 25, 2017 03:27
-
-
Save nethoncho/99e253de68eb97188f093fea12716fc4 to your computer and use it in GitHub Desktop.
Postgresql database migration management
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
# https://github.com/salsita/node-pg-migrate | |
npm install node-pg-migrate |
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
{ | |
"db": "postgres://meteor:meteor@localhost:5432/meteor" | |
} |
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
exports.up = (pgm, run) => { | |
pgm.createTable({name: 'players'}, | |
{ | |
id: {type: 'serial', notNull: true}, | |
name: {type: 'varchar(50)', unique: true}, | |
score: {type: 'integer', notNull: true} | |
}, | |
{ | |
ifNotExists: true, | |
constraints: {primaryKey: 'id'} | |
}); | |
run(); | |
}; | |
exports.down = (pgm, run) => { | |
pgm.dropTable('players', { ifExists: true, cascade: true }); | |
run(); | |
}; |
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
exports.up = (pgm, run) => { | |
pgm.sql('INSERT INTO players (name, score) VALUES (\'Kepler\', 40),(\'Leibniz\',50),(\'Maxwell\',60),(\'Planck\',70);'); | |
run(); | |
}; | |
exports.down = (pgm, run) => { | |
pgm.sql('DELETE FROM players;'); | |
run(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment