Skip to content

Instantly share code, notes, and snippets.

@Hum4n01d
Created January 3, 2018 00:17
Show Gist options
  • Save Hum4n01d/7d1bfa48bd914285da7cff375a09975e to your computer and use it in GitHub Desktop.
Save Hum4n01d/7d1bfa48bd914285da7cff375a09975e to your computer and use it in GitHub Desktop.
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)
})
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