elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.53k stars 1.2k forks source link

[BUG] Elsa 3.3 is incompatible with existing 3.1 and 3.2 databases #6103

Closed Suchiman closed 2 weeks ago

Suchiman commented 2 weeks ago

Description

If you're upgrading an Elsa v3.1 or v3.2 project to v3.3, you'll run into an error, saying that "WorkflowDefintions table already exists".

Steps to Reproduce

  1. Create a project with Elsa 3.2 using EFC + SqlServer for example.
  2. Run it once to have the Schema created
  3. Upgrade Elsa nugets to 3.3
  4. Run it again
  5. WorkflowDefintions table already exists error will show up

Expected Behavior

Just works and silently upgrades the db schema to 3.3

Actual Behavior

Crashes

Root cause

In #6059 you removed all existing migrations and created a new V3_3 migration. The way how migrations in EFC works, is that it enumerates all migrations in the assembly, then consults the __EFMigrationsHistory table and executes all migrations not listed in that table. Since V3_3 is not listed, it will be executed, but since you've removed all migrations, V3_3 does contain the entire schema and not just the delta from V3_2, meaning it will attempt to create tables that already exist and fail. The proper procedure to reset all migrations in a safe way is listed here https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations

sfmskywalker commented 2 weeks ago

I see. I should not have deleted the V3_0, V3_1 and V3_2 migrations, only the V3_3 (which will break only those who are on the 3.3 preview/rc).