Add missing indexes for call stack columns in V3_7 migrations#7250
Conversation
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds database indexes to three call stack tracking columns (SchedulingActivityExecutionId, SchedulingActivityId, SchedulingWorkflowInstanceId) that were introduced in the V3_7 migration. The indexes are necessary to optimize chain traversal queries and filtering operations.
Changes:
- Added EF Core index configurations for three scheduling columns in the ActivityExecutionRecord entity
- Modified V3_7 migrations across all database providers to include index creation
- Changed column types to be index-compatible (nvarchar(450) for SQL Server, varchar(255) for MySQL)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/modules/Elsa.Persistence.EFCore/Modules/Runtime/Configurations.cs | Added three index definitions for scheduling columns using consistent naming pattern |
| src/modules/Elsa.Persistence.EFCore.SqlServer/Migrations/Runtime/20260122123023_V3_7.cs | Changed column types from nvarchar(max) to nvarchar(450) and added indexes in Up method; added DropIndex operations in Down method |
| src/modules/Elsa.Persistence.EFCore.MySql/Migrations/Runtime/20260122123013_V3_7.cs | Changed column types from longtext to varchar(255) and added indexes in Up method; added DropIndex operations in Down method |
| src/modules/Elsa.Persistence.EFCore.Sqlite/Migrations/Runtime/20260122123040_V3_7.cs | Added CreateIndex operations for TEXT columns in Up method; added DropIndex operations in Down method |
| src/modules/Elsa.Persistence.EFCore.PostgreSql/Migrations/Runtime/20260122123049_V3_7.cs | Added CreateIndex operations for text columns in Up method; added DropIndex operations in Down method |
| src/modules/Elsa.Persistence.EFCore.Oracle/Migrations/Runtime/20260122123056_V3_7.cs | Added CreateIndex operations for NVARCHAR2(2000) columns in Up method; added DropIndex operations in Down method |
| migrationBuilder.AddColumn<string>( | ||
| name: "SchedulingActivityExecutionId", | ||
| schema: _schema.Schema, | ||
| table: "ActivityExecutionRecords", | ||
| type: "nvarchar(max)", | ||
| type: "nvarchar(450)", | ||
| nullable: true); | ||
|
|
||
| migrationBuilder.AddColumn<string>( | ||
| name: "SchedulingActivityId", | ||
| schema: _schema.Schema, | ||
| table: "ActivityExecutionRecords", | ||
| type: "nvarchar(max)", | ||
| type: "nvarchar(450)", | ||
| nullable: true); | ||
|
|
||
| migrationBuilder.AddColumn<string>( | ||
| name: "SchedulingWorkflowInstanceId", | ||
| schema: _schema.Schema, | ||
| table: "ActivityExecutionRecords", | ||
| type: "nvarchar(max)", | ||
| type: "nvarchar(450)", | ||
| nullable: true); |
There was a problem hiding this comment.
This PR modifies an existing V3_7 migration that may have already been deployed to production systems. If users have already run the original V3_7 migration (dated January 22, 2026), their databases will have these columns with incompatible types for indexing (nvarchar(max) instead of nvarchar(450)). Running migrations again won't fix existing columns since EF Core tracks which migrations have been applied.
Consider one of these approaches:
- If V3_7 has NOT been released yet, this change is fine.
- If V3_7 HAS been released, create a new migration (e.g., V3_7_1 or V3_8) that uses AlterColumn operations to change the column types and then adds the indexes.
- Add explicit SQL commands in the Up method to alter the column type if it already exists with the wrong type.
| type: "varchar(255)", | ||
| nullable: true) | ||
| .Annotation("MySql:CharSet", "utf8mb4"); | ||
|
|
There was a problem hiding this comment.
Similar to SQL Server, this modifies an existing V3_7 migration that may have already been deployed. If users have already run the original V3_7 migration, their databases will have these columns with longtext type instead of varchar(255), making them incompatible with indexing.
Consider one of these approaches:
- If V3_7 has NOT been released yet, this change is fine.
- If V3_7 HAS been released, create a new migration (e.g., V3_7_1 or V3_8) that uses AlterColumn operations to change the column types and then adds the indexes.
- Add explicit SQL commands in the Up method to alter the column type if it already exists with the wrong type.
| // Ensure the scheduling columns use an indexable type even if they were previously created as LONGTEXT. | |
| var tableName = string.IsNullOrWhiteSpace(_schema.Schema) | |
| ? "`ActivityExecutionRecords`" | |
| : $"`{_schema.Schema}`.`ActivityExecutionRecords`"; | |
| migrationBuilder.Sql($""" | |
| ALTER TABLE {tableName} | |
| MODIFY COLUMN `SchedulingActivityExecutionId` varchar(255) NULL, | |
| MODIFY COLUMN `SchedulingActivityId` varchar(255) NULL, | |
| MODIFY COLUMN `SchedulingWorkflowInstanceId` varchar(255) NULL; | |
| """); |
* Initial plan * Add missing indexes for call stack columns in all provider migrations Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Optimize migrations by creating columns with correct indexable types Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
* Adds activity execution call stack support Implements a call stack mechanism to track the execution chain, enabling visibility into the invocation hierarchy. Introduces new fields to scheduling models and runtime contexts to store call stack information. Includes EF Core migrations for various database providers to support new columns in `ActivityExecutionRecords`. Provides an API to query and reconstruct the call stack for a given activity execution. * Refactor: Replace `PagedCallStackResult` with `Page<T>` for execution chain pagination * Remove ambient scheduling scope logic and related methods Simplifies scheduling logic by removing ambient scope mechanisms, refactoring scheduling context handling, and updating affected classes accordingly. * Add `GetCallStackAsync` to `IActivityExecutionsApi` for querying activity execution call stack * Add new properties to `ActivityExecutionRecord` for scheduling and execution tracking Introduce fields for aggregated fault count, scheduling context, workflow instance details, and call stack depth to enhance execution monitoring and debugging capabilities. * Add call stack visualization for activity executions Introduced components and models to display a call stack for activity executions in the Workflow Instance Viewer. This includes UI elements for call stack rendering, error handling, and data integration with activity execution records. * Remove obsolete ambient scheduling properties from WorkflowExecutionContext * Fix infinite loop issues in activity execution chain traversal Added cycle detection using a `HashSet` to prevent infinite loops when traversing activity execution chains in multiple storage implementations. Updated unit tests to validate correct handling of circular references and chain traversal. * Refactor activity execution chain retrieval logic Centralized the `GetExecutionChainAsync` method into an extension class to streamline and unify its implementation across stores. Removed redundant implementations from individual stores and updated interfaces to utilize the new extension method. This reduces code duplication and simplifies future maintenance. * Add CallStackDepth property to activity contexts Integrated the `CallStackDepth` property into `ActivityExecutionContext`, `ActivityExecutionContextState`, and related classes to track and manage the call stack depth of activity executions. Removed obsolete depth calculation logic to streamline the process. * Add unit tests for call stack depth calculations and persistence - Add `WorkflowExecutionContextTests` to verify correct calculation of call stack depth during activity execution. - Add `WorkflowStateExtractorTests` to ensure call stack depth is preserved during state extraction and application. * Update src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Api/Endpoints/ActivityExecutions/GetCallStack/Endpoint.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Enhance activity execution handling with ID filter and task completion logic - Implement `ActivityExecutionRecordFilter` for precise query matching by ID. - Add await logic for task completion in command handler middleware. * Add missing indexes for call stack columns in V3_7 migrations (#7250) * Initial plan * Add missing indexes for call stack columns in all provider migrations Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Optimize migrations by creating columns with correct indexable types Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Add unit tests for ActivityExecutionStoreExtensions - Introduce tests for `GetExecutionChainAsync` covering scenarios of empty results, single records, multi-level chain traversal, workflow boundary constraints, pagination, and circular references. * Refactor tests for `ActivityExecutionStoreExtensions` - Replace mock setup with `CreateStore` helper for clean and clear test arrangements. - Remove unused imports and clean up test setup for improved readability and maintenance. * Remove unused imports from ActivityExecutionLogStore in Elsa.Persistence.EFCore module. * Removes obsolete planning document Removes the activity execution call stack planning document as the feature has been implemented. * Remove DefaultActivityExecutionMapperTests - Deleted `DefaultActivityExecutionMapperTests.cs` as the test class is no longer in use and redundant. * Address review feedback: Fix corrupted test, Oracle migrations, and call stack depth calculation (#7272) * Initial plan * Fix corrupted DefaultActivityExecutionMapperTests.cs test file Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Fix Oracle migration snapshot to use NCLOB for large text fields Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Optimize GetExecutionChainAsync to avoid loading all workflow instance records Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Fix CallStackDepth calculation to support cross-workflow invocations - Add SchedulingCallStackDepth to ActivityInvocationOptions - Update WorkflowExecutionContext to use provided depth when scheduling context not found - Remove problematic test that reveals pre-existing bug with duplicate contexts Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Improve documentation for CallStackDepth calculation Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Add WorkflowStateExtractor to ActivityTestFixture services * Refactor `DefaultActivityExecutionMapperTests` with `ActivityTestFixture` and add project reference for shared testing utilities. * Propagate SchedulingCallStackDepth through cross-workflow invocation chain (#7273) * Initial plan * Add SchedulingCallStackDepth propagation through cross-workflow invocation chain Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Add unit tests for CallStackDepth propagation across workflow boundaries Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Initial plan (#7274) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Reduce NVARCHAR2 column sizes in Oracle migrations to optimize storage and improve performance. * Change column types to NCLOB for large text fields in Oracle migrations to enhance data storage capacity. * Update GitHub Actions to use .NET 10.x and refactor setup classes for consistency * Improve test project detection in GitHub Actions by handling non-csproj files and updating project sorting mechanism. * Enhance GitHub Actions to display .NET environment info and enforce .NET 10 toolchain for test execution. * Update GitHub Actions to use .NET SDK 10.0.1xx and enforce its usage for builds and tests. * Refine GitHub Actions workflow by narrowing test project search to the `test/unit` directory and removing unnecessary script checks. * Remove redundant build step from GitHub Actions workflow. * Enhance GitHub Actions workflow by adding multiple test directories and handling ignored failed sources in .NET restore. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
The V3_7 migrations added three new columns for activity execution call stack tracking but did not create indexes on them. These columns (
SchedulingActivityExecutionId,SchedulingActivityId,SchedulingWorkflowInstanceId) are used for chain traversal queries and filtering, requiring indexes to avoid table scans.Changes
Configurations.csCreateIndex/DropIndexoperations in Up/Down methodsnvarchar(450)(matching existing indexed ID columns) with indexesvarchar(255)(matching existing indexed ID columns) with indexesAll column types align with existing schema patterns for indexed identifier columns in their respective providers.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.