recipe_app/backend/migrations/20250708205938_create_ingredients_table.js

43 lines
1.3 KiB
JavaScript

/**
* @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('instruction');
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')
};