elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

Fix SQLite migrations incorrectly using schema operations

Open Copilot opened this issue 3 months ago • 0 comments

SQLite migrations V3_4, V3_5, and V3_6 incorrectly attempted schema operations (EnsureSchema, RenameTable with newSchema, schema qualifiers on DDL) that SQLite doesn't support, causing tables to become inaccessible. This manifested as the WorkflowInstances table appearing empty while other tables contained data.

Changes

Removed schema operations from SQLite migrations:

  • V3_4 (Management, Runtime, Labels, Identity, Tenants, Alterations): Removed EnsureSchema() and RenameTable() calls
  • V3_5 (Runtime): Removed schema: parameters from AddColumn, AlterColumn, CreateIndex
  • V3_6 (Management): Removed schema: parameters from AddColumn, DropColumn

Before (V3_4 Management):

migrationBuilder.EnsureSchema(name: _schema.Schema);
migrationBuilder.RenameTable(
    name: "WorkflowInstances",
    newName: "WorkflowInstances",
    newSchema: _schema.Schema);
migrationBuilder.AddColumn<bool>(
    name: "IsExecuting",
    schema: _schema.Schema,  // ← Problem
    table: "WorkflowInstances",
    type: "INTEGER");

After:

// SQLite does not support schemas, so we only add the column without schema qualifiers
migrationBuilder.AddColumn<bool>(
    name: "IsExecuting",
    table: "WorkflowInstances",
    type: "INTEGER");

Impact

Users who already applied V3_4+ migrations may need to recreate their SQLite databases. New installations will work correctly.

Original prompt

This section details on the original issue you should resolve

<issue_title>The WorkflowInstances table is always empty when using SQLite as the storage, while other tables have records.</issue_title> <issue_description>## Description 使用的是3.5.1版本,升级后也是这样 services.AddElsa(elsa => { var dbConn = $"Data Source=d:\\eap_workflow.db"; elsa.UseWorkflows(workflow => { workflow.WithWorkflowExecutionPipeline(pileline => pileline.UseMiddleware<WorkflowExecMiddleware>().UseExceptionHandling().UseDefaultActivityScheduler()); workflow.WithActivityExecutionPipeline(pileline => pileline.UseMiddleware<ActivityExecMiddleware>().UseDefaultActivityInvoker()); }); elsa.UseWorkflowManagement(management => { management.UseEntityFrameworkCore(efcore => { efcore.UseSqlite(dbConn); }); }); elsa.UseWorkflowRuntime(runtime => { runtime.UseEntityFrameworkCore(efcore => { efcore.UseSqlite(dbConn); }); }); elsa.UseJavaScript(); elsa.UseRetention(retention => { retention.SweepInterval = TimeSpan.FromDays(1); retention.AddDeletePolicy("delete 2 days", provider => { var threshold = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(2)); return new RetentionWorkflowInstanceFilter() { TimestampFilters = [ new TimestampFilter() { Column = nameof(WorkflowInstance.FinishedAt), Operator = TimestampFilterOperator.LessThanOrEqual, Timestamp = threshold } ], WorkflowStatus = WorkflowStatus.Finished }; }); }); }).AddActivitiesFrom<TActivity>().AddWorkflowsFrom<TActivity>();

Steps to Reproduce

</issue_description>

<agent_instructions>Try and see if you can reproduce this with a brand new ASP.NET Core project that references Elsa 3.5.1 packages using the startup code provided by the OP.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@sfmskywalker Can you perhaps share a sample project that reproduces this issue?
  • Fixes elsa-workflows/elsa-core#7124

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

Copilot avatar Dec 03 '25 14:12 Copilot