Created
January 3, 2018 00:17
-
-
Save Hum4n01d/7d1bfa48bd914285da7cff375a09975e to your computer and use it in GitHub Desktop.
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
const bookshelf = require('../bookshelf') | |
const Definition = bookshelf.Model.extend({ | |
tableName: 'definitions' | |
}) | |
const Player = bookshelf.Model.extend({ | |
tableName: 'players', | |
game: () => this.belongsTo(Game, 'game.id') | |
}) | |
const Game = bookshelf.Model.extend({ | |
tableName: 'games', | |
definitions: () => this.hasMany(Definition), | |
players: () => this.hasMany(Player) | |
}) |
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 = knex => { | |
return knex.schema | |
.createTable('games', table => { | |
table.increments('id').primary() | |
table.string('name') | |
table.timestamps() | |
}).createTable('definitions', table => { | |
table.increments('id').primary() | |
table.string('definition') | |
table.integer('game_id').references('game.id') | |
}).createTable('players', table => { | |
table.increments('id').primary() | |
table.string('username') | |
table.string('email') | |
table.string('password') | |
table.integer('game_id').references('game.id') | |
}) | |
} | |
exports.down = knex => { | |
return knex.schema | |
.dropTable('games') | |
.dropTable('definitions') | |
.dropTable('players') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment