Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created June 30, 2018 21:17
Show Gist options
  • Save fdjones/2a7d5d5b528a88e54d44dcaaf83878f8 to your computer and use it in GitHub Desktop.
Save fdjones/2a7d5d5b528a88e54d44dcaaf83878f8 to your computer and use it in GitHub Desktop.
exports.up = function (knex, Promise) {
return knex.schema.createTableIfNotExists('authors', function (table) {
table.increments('uid').primary();
table.string('name');
table.string('password');
table.string('email');
})
.then(res => {
return knex.schema.createTableIfNotExists('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.createTableIfNotExists('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.dropTableIfExists('authors');
knex.schema.dropTableIfExists('thunks');
knex.schema.dropTableIfExists('comments');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment