db tables
This commit is contained in:
parent
58ef46a85c
commit
c8d58db08a
1 changed files with 43 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema.createTable('ingredients', function (table) {
|
||||||
|
table.increments('id').primary();
|
||||||
|
table.string('name').notNullable().unique();
|
||||||
|
table.string('type');
|
||||||
|
table.string('notes');
|
||||||
|
table.timestamps(true, true);
|
||||||
|
}).
|
||||||
|
createTable('recipe_ingredients', function (table) {
|
||||||
|
table.increments('id').primary();
|
||||||
|
table.integer('recipe_id').notNullable();
|
||||||
|
table.integer('ingredient_id').notNullable();
|
||||||
|
table.string('quantity').notNullable();
|
||||||
|
table.string('unit').notNullable();
|
||||||
|
table.string('notes');
|
||||||
|
table.index(['recipe_id']);
|
||||||
|
table.index(['ingredient_id']);
|
||||||
|
table.timestamps(true, true);
|
||||||
|
}).
|
||||||
|
createTable('recipe_steps', function (table) {
|
||||||
|
table.increments('id').primary();
|
||||||
|
table.integer('recipe_id');
|
||||||
|
table.integer('step_number');
|
||||||
|
table.string('instructions');
|
||||||
|
table.unique(['recipe_id', 'step_number']);
|
||||||
|
table.index(['recipe_id'])
|
||||||
|
table.timestamps(true, true);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.down = function (knex) {
|
||||||
|
return knex.schema.dropTableIfExists('ingredients')
|
||||||
|
.dropTableIfExists('recipe_ingredients')
|
||||||
|
.dropTableIfExists('recipe_steps')
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue