Skip to content

Move SQL JSON helper function setup from runtime initialization into EF Core migrations#1314

Closed
SebastianStehle with Copilot wants to merge 1 commit into
masterfrom
copilot/migrate-initializeasync-jsonfunctions
Closed

Move SQL JSON helper function setup from runtime initialization into EF Core migrations#1314
SebastianStehle with Copilot wants to merge 1 commit into
masterfrom
copilot/migrate-initializeasync-jsonfunctions

Conversation

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor

JsonFunction.InitializeAsync was creating provider-specific SQL JSON helper functions at app startup instead of as part of schema evolution. This moves that setup into EF Core migrations for each SQL dialect so migrated databases consistently get the required functions through the normal migration path.

  • Provider migrations

    • Add app migrations for MySQL, Postgres, and SQL Server that create the JSON helper functions from the existing embedded SQL resources.
    • Implement corresponding Down behavior so function lifecycle stays owned by migrations.
  • Shared migration plumbing

    • Add a small shared helper to load the embedded SQL resources and apply them in a provider-appropriate way:
      • Postgres executes the full script.
      • MySQL / SQL Server split and apply individual statements.
  • Runtime initialization

    • Remove the app-level SqlDialectInitializer<TContext> registration from EF service wiring so app startup no longer recreates these functions outside migration execution.
  • Migration coverage

    • Extend provider migration tests to assert the helper functions are available after migrations complete, rather than only asserting that some migration ran.
protected override void Up(MigrationBuilder migrationBuilder)
{
    JsonFunctionMigration.Create(
        migrationBuilder,
        typeof(PostgresDialect),
        "Squidex.Providers.Postgres.json_function.sql",
        splitStatements: false);
}

Agent-Logs-Url: https://github.com/Squidex/squidex/sessions/7f1356a2-bd23-4452-a915-c46854bc604d

Co-authored-by: SebastianStehle <1236435+SebastianStehle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants