Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created June 23, 2018 12:29
Show Gist options
  • Save fdjones/25cfea816970b81e7c9590f003726ef5 to your computer and use it in GitHub Desktop.
Save fdjones/25cfea816970b81e7c9590f003726ef5 to your computer and use it in GitHub Desktop.
exports.up = function (knex, Promise) {
return knex.schema.createTable('authors', function (table) {
table.increments('uid').primary();
table.string('name');
table.string('password');
table.string('email');
})
.then(res => {
return knex.schema.createTable('thunks', function (table) {
table.increments('id').primary();
table.string('title');
table.string('body');
table.integer('author_id')
.references('uid')
.inTable('authors');
table.dateTime('postDate');
})
})
.then(res => {
return knex.schema.createTable('comments', function(table) {
table.increments('id').primary();
table.string('body');
table.integer('author_id')
.references('uid')
.inTable('authors');
table.integer('post_id')
.references('id')
.inTable('thunks');
table.dateTime('postDate');
})
})
};
exports.down = function (knex, Promise) {
knex.schema.dropTable('authors');
knex.schema.dropTable('thunks');
knex.schema.dropTable('comments');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment