mirror of https://github.com/Squidex/squidex.git
Browse Source
- Replace SqlDialectInitializer startup logic with proper EF Core migrations for all three providers (MySQL, SQL Server, Postgres) - SQL Server: uses CREATE OR ALTER FUNCTION (idempotent, no DROP needed) - MySQL: uses DROP FUNCTION IF EXISTS + CREATE FUNCTION in migration - Remove SqlDialectInitializer registration from production ServiceExtensions - Add migration tests: idempotency and upgrade-from-pre-migration-databasepull/1313/head
11 changed files with 5291 additions and 34 deletions
File diff suppressed because it is too large
@ -0,0 +1,67 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Squidex.Providers.MySql; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Squidex.Providers.MySql.App.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddJsonFunctions : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
var assembly = typeof(MySqlDialect).Assembly; |
|||
|
|||
using var sqlStream = assembly.GetManifestResourceStream("Squidex.Providers.MySql.json_function.sql")!; |
|||
using var reader = new StreamReader(sqlStream); |
|||
|
|||
var sqlText = reader.ReadToEnd(); |
|||
var statements = sqlText.Split(";;", System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries); |
|||
|
|||
foreach (var statement in statements) |
|||
{ |
|||
migrationBuilder.Sql(statement, suppressTransaction: true); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
var functions = new[] |
|||
{ |
|||
"json_empty", |
|||
"json_exists", |
|||
"json_null_equals", |
|||
"json_null_notequals", |
|||
"json_text_contains", |
|||
"json_text_endswith", |
|||
"json_text_equals", |
|||
"json_text_greaterthan", |
|||
"json_text_greaterthanorequal", |
|||
"json_text_in", |
|||
"json_text_lessthan", |
|||
"json_text_lessthanorequal", |
|||
"json_text_matchs", |
|||
"json_text_notequals", |
|||
"json_text_startswith", |
|||
"json_boolean_equals", |
|||
"json_boolean_in", |
|||
"json_boolean_notequals", |
|||
"json_number_equals", |
|||
"json_number_greaterthan", |
|||
"json_number_greaterthanorequal", |
|||
"json_number_in", |
|||
"json_number_lessthan", |
|||
"json_number_lessthanorequal", |
|||
"json_number_notequals", |
|||
}; |
|||
|
|||
foreach (var function in functions) |
|||
{ |
|||
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS {function}", suppressTransaction: true); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,59 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Squidex.Providers.Postgres; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Squidex.Providers.Postgres.App.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddJsonFunctions : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
var assembly = typeof(PostgresDialect).Assembly; |
|||
|
|||
using var sqlStream = assembly.GetManifestResourceStream("Squidex.Providers.Postgres.json_function.sql")!; |
|||
using var reader = new StreamReader(sqlStream); |
|||
|
|||
var sqlText = reader.ReadToEnd(); |
|||
var statements = sqlText.Split(";;", System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries); |
|||
|
|||
foreach (var statement in statements) |
|||
{ |
|||
migrationBuilder.Sql(statement); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_empty(jsonb)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_exists(jsonb)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_null_equals(jsonb)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_null_notequals(jsonb)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_equals(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_notequals(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_lessthan(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_lessthanorequal(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_greaterthan(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_greaterthanorequal(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_contains(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_startswith(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_endswith(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_matchs(jsonb, text)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_text_in(jsonb, text[])"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_equals(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_notequals(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_lessthan(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_lessthanorequal(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_greaterthan(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_greaterthanorequal(jsonb, numeric)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_number_in(jsonb, numeric[])"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_boolean_equals(jsonb, boolean)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_boolean_notequals(jsonb, boolean)"); |
|||
migrationBuilder.Sql("DROP FUNCTION IF EXISTS jsonb_boolean_in(jsonb, boolean[])"); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,64 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Squidex.Providers.SqlServer; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Squidex.Providers.SqlServer.App.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class AddJsonFunctions : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
var assembly = typeof(SqlServerDialect).Assembly; |
|||
|
|||
using var sqlStream = assembly.GetManifestResourceStream("Squidex.Providers.SqlServer.json_function.sql")!; |
|||
using var reader = new StreamReader(sqlStream); |
|||
|
|||
var sqlText = reader.ReadToEnd(); |
|||
var statements = sqlText.Split(";;", System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries); |
|||
|
|||
foreach (var statement in statements) |
|||
{ |
|||
migrationBuilder.Sql(statement); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
var functions = new[] |
|||
{ |
|||
"dbo.json_empty", |
|||
"dbo.json_exists", |
|||
"dbo.json_null_equals", |
|||
"dbo.json_null_notequals", |
|||
"dbo.json_text_contains", |
|||
"dbo.json_text_endswith", |
|||
"dbo.json_text_equals", |
|||
"dbo.json_text_greaterthan", |
|||
"dbo.json_text_greaterthanorequal", |
|||
"dbo.json_text_lessthan", |
|||
"dbo.json_text_lessthanorequal", |
|||
"dbo.json_text_matchs", |
|||
"dbo.json_text_notequals", |
|||
"dbo.json_text_startswith", |
|||
"dbo.json_boolean_equals", |
|||
"dbo.json_boolean_notequals", |
|||
"dbo.json_number_equals", |
|||
"dbo.json_number_greaterthan", |
|||
"dbo.json_number_greaterthanorequal", |
|||
"dbo.json_number_lessthan", |
|||
"dbo.json_number_lessthanorequal", |
|||
"dbo.json_number_notequals", |
|||
}; |
|||
|
|||
foreach (var function in functions) |
|||
{ |
|||
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS {function}"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue