Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ public static async Task InitializeAsync(DbContext dbContext,
sqlText = sqlText.Replace("}", "}}", StringComparison.Ordinal);

var statements = sqlText.Split(";;", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
// We want to filter out the drop statements and multiple function creations are not supported.
foreach (var statement in statements)
{
#if RELEASE
if (statement.StartsWith("DROP", StringComparison.Ordinal))
{
continue;
}
#endif
await dbContext.Database.ExecuteSqlRawAsync(statement, ct);
}
}
Expand Down
Loading
Loading