diff --git a/libs/database/src/migrations/m20231016_create_collection_to_entity.rs b/libs/database/src/migrations/m20231016_create_collection_to_entity.rs index 533b7773fb..495d3adf83 100644 --- a/libs/database/src/migrations/m20231016_create_collection_to_entity.rs +++ b/libs/database/src/migrations/m20231016_create_collection_to_entity.rs @@ -37,7 +37,7 @@ pub static ENTITY_ID_SQL: &str = indoc! { r#" "exercise_id", "workout_id" ) - ) STORED; + ) STORED "# }; pub static ENTITY_LOT_SQL: &str = indoc! { r#" GENERATED ALWAYS AS ( @@ -48,7 +48,7 @@ pub static ENTITY_LOT_SQL: &str = indoc! { r#" WHEN "exercise_id" IS NOT NULL THEN 'exercise' WHEN "workout_id" IS NOT NULL THEN 'workout' END - ) STORED; + ) STORED "# }; #[derive(Iden)] diff --git a/libs/database/src/migrations/m20240724_zzz_new_generated_collection_to_entity_columns.rs b/libs/database/src/migrations/m20240724_zzz_new_generated_collection_to_entity_columns.rs index 72bf8845db..b4691d8f68 100644 --- a/libs/database/src/migrations/m20240724_zzz_new_generated_collection_to_entity_columns.rs +++ b/libs/database/src/migrations/m20240724_zzz_new_generated_collection_to_entity_columns.rs @@ -13,7 +13,7 @@ impl MigrationTrait for Migration { db.execute_unprepared( r#" ALTER TABLE collection_to_entity -ADD COLUMN entity_id text GENERATED ALWAYS AS ( +ADD COLUMN IF NOT EXISTS entity_id text GENERATED ALWAYS AS ( COALESCE(metadata_id, person_id, metadata_group_id, @@ -26,7 +26,7 @@ ADD COLUMN entity_id text GENERATED ALWAYS AS ( db.execute_unprepared( r#" ALTER TABLE collection_to_entity -ADD COLUMN entity_lot text GENERATED ALWAYS AS ( +ADD COLUMN IF NOT EXISTS entity_lot text GENERATED ALWAYS AS ( CASE WHEN metadata_id IS NOT NULL THEN 'metadata' WHEN person_id IS NOT NULL THEN 'person'