Skip to content

Instantly share code, notes, and snippets.

@nethoncho
Last active October 25, 2017 03:27
Show Gist options
  • Save nethoncho/99e253de68eb97188f093fea12716fc4 to your computer and use it in GitHub Desktop.
Save nethoncho/99e253de68eb97188f093fea12716fc4 to your computer and use it in GitHub Desktop.
Postgresql database migration management
# https://github.com/salsita/node-pg-migrate
npm install node-pg-migrate
{
"db": "postgres://meteor:meteor@localhost:5432/meteor"
}
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();
};
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