Глобальный рефакторинг пространств имён
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Pf2e.Database.Model;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Pf2e.Database.Migrations
|
||||
{
|
||||
[DbContext(typeof(Pf2eDbContext))]
|
||||
[Migration("20250418062358_Function")]
|
||||
partial class Function
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Pf2e.Database.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class Function : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION f_drop_tables()
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
BEGIN
|
||||
EXECUTE
|
||||
(SELECT 'DROP TABLE '
|
||||
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|
||||
|| ' CASCADE;'
|
||||
FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
);
|
||||
END
|
||||
$func$;
|
||||
"""
|
||||
);
|
||||
migrationBuilder.Sql(
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION f_permission_tables(_username text)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
DECLARE
|
||||
_tbl text;
|
||||
_sch text;
|
||||
BEGIN
|
||||
FOR _sch, _tbl IN
|
||||
SELECT schemaname, tablename
|
||||
FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
LOOP
|
||||
EXECUTE format('ALTER TABLE %I.%I OWNER TO %I', _sch, _tbl, _username);
|
||||
END LOOP;
|
||||
END
|
||||
$func$;
|
||||
"""
|
||||
);
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION locale_search(data jsonb, search_value text)
|
||||
RETURNS boolean
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
BEGIN
|
||||
RETURN jsonb_path_exists(data, '$.** ? (@ == $val)', jsonb_build_object('val', search_value));
|
||||
END;
|
||||
$func$;
|
||||
"""
|
||||
);
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION locale_search_array(data jsonb, search_values text[])
|
||||
RETURNS boolean
|
||||
LANGUAGE plpgsql AS
|
||||
$func$
|
||||
BEGIN
|
||||
RETURN EXISTS (
|
||||
SELECT 1
|
||||
FROM unnest(search_values) AS val
|
||||
WHERE jsonb_path_exists(data, '$.** ? (@ == $val)', jsonb_build_object('val', val))
|
||||
);
|
||||
END;
|
||||
$func$;
|
||||
"""
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("DROP FUNCTION f_truncate_tables;");
|
||||
migrationBuilder.Sql("DROP FUNCTION f_drop_tables;");
|
||||
migrationBuilder.Sql("DROP FUNCTION f_permission_tables;");
|
||||
migrationBuilder.Sql("DROP FUNCTION locale_search;");
|
||||
migrationBuilder.Sql("DROP FUNCTION locale_search_array;");
|
||||
}
|
||||
}
|
||||
+2997
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user