CREATE TABLE `production_recipe_lines` (
	`id` int AUTO_INCREMENT NOT NULL,
	`recipeId` int NOT NULL,
	`stockItemId` int NOT NULL,
	`sequence` int NOT NULL,
	`quantityPerBatch` int NOT NULL,
	`stepName` varchar(160),
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `production_recipe_lines_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `production_recipes` (
	`id` int AUTO_INCREMENT NOT NULL,
	`finishedStockItemId` int NOT NULL,
	`version` varchar(40) NOT NULL,
	`name` varchar(160) NOT NULL,
	`expectedYieldPercent` int NOT NULL DEFAULT 100,
	`isActive` boolean NOT NULL DEFAULT true,
	`createdByUserId` int,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `production_recipes_id` PRIMARY KEY(`id`),
	CONSTRAINT `production_recipes_item_version_unique` UNIQUE(`finishedStockItemId`,`version`)
);
--> statement-breakpoint
ALTER TABLE `production_orders` ADD `recipeId` int;--> statement-breakpoint
CREATE INDEX `production_recipe_lines_recipe_index` ON `production_recipe_lines` (`recipeId`);