db tables

This commit is contained in:
fred 2025-07-08 15:29:37 -07:00
parent 58ef46a85c
commit c8d58db08a

View file

@ -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')
};