From b6d08a8d245b2dd30768f0fd30911944ca91472a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Jun 2024 20:55:35 -0400 Subject: [PATCH] Fixed migration --- server/src/migrations/V60__recipe_book.sql | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/server/src/migrations/V60__recipe_book.sql b/server/src/migrations/V60__recipe_book.sql index d34e9364e0..67125007fc 100644 --- a/server/src/migrations/V60__recipe_book.sql +++ b/server/src/migrations/V60__recipe_book.sql @@ -2,13 +2,15 @@ CREATE TEMP TABLE _temp_character_recipe_pairings ( temp_recipe_book_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, character_id INT NOT NULL, - recipe_book_id INT + recipe_book_id INT, + recipe_item_id INT ); INSERT INTO _temp_character_recipe_pairings SELECT NULL, i.item_id, + NULL, NULL FROM item i WHERE i.item_definition_id = 'veloren.core.pseudo_containers.character'; @@ -16,11 +18,19 @@ WHERE i.item_definition_id = 'veloren.core.pseudo_containers.character'; UPDATE _temp_character_recipe_pairings SET recipe_book_id = ((SELECT MAX(entity_id) FROM entity) + temp_recipe_book_id); +UPDATE _temp_character_recipe_pairings +SET recipe_item_id = ((SELECT MAX(entity_id) FROM entity) + (SELECT MAX(temp_recipe_book_id) FROM _temp_character_recipe_pairings) + temp_recipe_book_id); + INSERT INTO entity SELECT t.recipe_book_id FROM _temp_character_recipe_pairings t; +-- Insert the new recipe book items, temporarily disabling foreign key constraints +-- due to the parent_container_item_id foreign key constraint not being satisfied +-- until the end of the query. +PRAGMA defer_foreign_keys = true; + INSERT INTO item SELECT t.recipe_book_id, @@ -29,4 +39,16 @@ SELECT t.recipe_book_id, 1, 'recipe_book', '' -FROM _temp_character_recipe_pairings t; \ No newline at end of file +FROM _temp_character_recipe_pairings t; + +INSERT +INTO item +SELECT t.recipe_item_id, + t.recipe_book_id, + 'common.items.recipes.default', + 1, + '0', + '{}' +FROM _temp_character_recipe_pairings t; + +PRAGMA defer_foreign_keys = false; \ No newline at end of file