Skip to content

Commit

Permalink
v2.7.0 (#61)
Browse files Browse the repository at this point in the history
* v2.7.0
- *Enhancement:* Require a means to add an explicitly named resource-based script outside of the automatic convention-based discovery; see new `MigrationArgs.AddScript`.
- *Enhancement:* Moving the [_Beef_](https://github.com/Avanade/beef)-based standardized SQL Server scripts (functions and stored procedures) to _DbEx_ to enable greater usage. New `MigrationArgs.IncludeExtendedSchemaScripts` extension method will add (leverages new `MigrationArgs.AddScript`).
- *Enhancement:* Added PostgreSQL equivalent standardized SQL Server scripts (functions and stored procedures).
- *Enhancement:* Added command-line option `-dso|--drop-schema-objects` to set `MigrationArgs.DropSchemaObjects` directly from the console.

* Fix test error.
  • Loading branch information
chullybun authored Oct 11, 2024
1 parent 169f2d6 commit e964495
Show file tree
Hide file tree
Showing 45 changed files with 714 additions and 21 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

Represents the **NuGet** versions.

## v2.7.0
- *Enhancement:* Require a means to add an explicitly named resource-based script outside of the automatic convention-based discovery; see new `MigrationArgs.AddScript`.
- *Enhancement:* Moving the [_Beef_](https://github.com/Avanade/beef)-based standardized SQL Server scripts (functions and stored procedures) to _DbEx_ to enable greater usage. New `MigrationArgs.IncludeExtendedSchemaScripts` extension method will add (leverages new `MigrationArgs.AddScript`).
- *Enhancement:* Added PostgreSQL equivalent standardized SQL Server scripts (functions and stored procedures).
- *Enhancement:* Added command-line option `-dso|--drop-schema-objects` to set `MigrationArgs.DropSchemaObjects` directly from the console.

## v2.6.1
- *Fixed:* Added `MigrationCommand.CreateMigrateAndCodeGen`. This can be useful in development scenarios where the `CodeGen` phase results in a new migration script that needs to be applied before any corresponding `Schema` operations are performed; in this case, a secondary
- *Fixed:* Added `MigrationCommand.CreateMigrateAndCodeGen`. This can be useful in development scenarios where the `CodeGen` phase results in a new migration script that needs to be applied before any corresponding `Schema` operations are performed; in this case, a secondary migration will be required.

## v2.6.0
- *Enhancement:* Added a `DbColumnSchema.SqlType2` that does _not_ include nullability.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.6.1</Version>
<Version>2.7.0</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/DbEx.MySql/DbEx.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database.MySql" Version="3.25.6" />
<PackageReference Include="CoreEx.Database.MySql" Version="3.27.0" />
<PackageReference Include="dbup-mysql" Version="5.0.44" />
</ItemGroup>

Expand Down
37 changes: 37 additions & 0 deletions src/DbEx.Postgres/Console/MigrationArgsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

using DbEx.Migration;
using System.Linq;

namespace DbEx.Postgres.Console
{
/// <summary>
/// Provides extension methods for <see cref="MigrationArgs"/>.
/// </summary>
public static class MigrationArgsExtensions
{
/// <summary>
/// Include the Postgres extended <b>Schema</b> scripts (stored procedures and functions) from <see href="https://github.com/Avanade/DbEx/tree/main/src/DbEx.Postgres/Resources/ExtendedSchema"/>.
/// </summary>
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
public static MigrationArgs IncludeExtendedSchemaScripts(this MigrationArgs args)
{
AddExtendedSchemaScripts(args);
return args;
}

/// <summary>
/// Include the Postgres extended <b>Schema</b> scripts (stored procedures and functions) from <see href="https://github.com/Avanade/DbEx/tree/main/src/DbEx.Postgres/Resources/ExtendedSchema"/>.
/// </summary>
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
public static void AddExtendedSchemaScripts<TArgs>(TArgs args) where TArgs : MigrationArgsBase<TArgs>
{
foreach (var rn in typeof(MigrationArgsExtensions).Assembly.GetManifestResourceNames().Where(x => x.StartsWith("DbEx.Postgres.Resources.ExtendedSchema.") && x.EndsWith(".sql")))
{
args.AddScript(MigrationCommand.Schema, typeof(MigrationArgsExtensions).Assembly, rn);
}
}
}
}
14 changes: 13 additions & 1 deletion src/DbEx.Postgres/DbEx.Postgres.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
<None Remove="Resources\JournalCreate.sql" />
<None Remove="Resources\JournalExists.sql" />
<None Remove="Resources\JournalPrevious.sql" />
<None Remove="Resources\ExtendedSchema\Functions\fn_get_tenant_id.sql" />
<None Remove="Resources\ExtendedSchema\Functions\fn_get_timestamp.sql" />
<None Remove="Resources\ExtendedSchema\Functions\fn_get_username.sql" />
<None Remove="Resources\ExtendedSchema\Functions\fn_get_user_id.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_set_session_context.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_authorization_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_business_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_concurrency_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_conflict_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_duplicate_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_not_found_exception.sql" />
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_validation_exception.sql" />
<None Remove="Resources\ScriptAlter_sql.hbs" />
<None Remove="Resources\ScriptCreate_sql.hbs" />
<None Remove="Resources\ScriptDefault_sql.hbs" />
Expand All @@ -42,7 +54,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database.Postgres" Version="3.25.6" />
<PackageReference Include="CoreEx.Database.Postgres" Version="3.27.0" />
<PackageReference Include="dbup-postgresql" Version="5.0.40" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

CREATE OR REPLACE FUNCTION fn_get_tenant_id(
"Override" TEXT = NULL
)
RETURNS TEXT
LANGUAGE plpgsql
AS $$
DECLARE "TenantId" TEXT;
BEGIN
IF "Override" IS NULL THEN
"TenantId" := current_setting('Session.TenantId', true);
ELSE
"TenantId" := "Override";
END IF;

RETURN "TenantId";
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

CREATE OR REPLACE FUNCTION fn_get_timestamp(
"Override" TIMESTAMP WITH TIME ZONE = NULL
)
RETURNS TIMESTAMP WITH TIME ZONE
LANGUAGE plpgsql
AS $$
DECLARE "Timestamp" TIMESTAMP WITH TIME ZONE;
BEGIN
"Timestamp" := CURRENT_TIMESTAMP;
IF "Override" IS NULL THEN
"Timestamp" := to_timestamp(current_setting('Session.Timestamp', true), 'YYYY-MM-DD"T"HH24:MI:SS.FF6');
IF "Timestamp" IS NULL THEN
"Timestamp" := CURRENT_TIMESTAMP;
END IF;
ELSE
"Timestamp" := "Override";
END IF;

RETURN "Timestamp";
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

CREATE OR REPLACE FUNCTION fn_get_user_id(
"Override" TEXT = NULL
)
RETURNS TEXT
LANGUAGE plpgsql
AS $$
DECLARE "UserId" TEXT;
BEGIN
IF "Override" IS NULL THEN
"UserId" := current_setting('Session.UserId', true);
ELSE
"UserId" := "Override";
END IF;

RETURN "UserId";
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef

CREATE OR REPLACE FUNCTION fn_get_username(
"Override" TEXT = NULL
)
RETURNS TEXT
LANGUAGE plpgsql
AS $$
DECLARE "Username" TEXT;
BEGIN
IF "Override" IS NULL THEN
"Username" := current_setting('Session.Username', true);
IF "Username" IS NULL THEN
"Username" := current_user;
END IF;
ELSE
"Username" := "Override";
END IF;

RETURN "Username";
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_set_session_context(
"Timestamp" TIMESTAMP WITH TIME ZONE = NULL,
"Username" TEXT = NULL,
"TenantId" TEXT = NULL,
"UserId" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "Timestamp" IS NOT NULL THEN
PERFORM set_config('Session.Timestamp', to_char("Timestamp", 'YYYY-MM-DD"T"HH24:MI:SS.FF6'), false);
END IF;

IF "Username" IS NOT NULL THEN
PERFORM set_config('Session.Username', "Username", false);
END IF;

IF "TenantId" IS NOT NULL THEN
PERFORM set_config('Session.TenantId', "TenantId", false);
END IF;

IF "UserId" IS NOT NULL THEN
PERFORM set_config('Session.UserId', "UserId", false);
END IF;
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_authorization_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56003';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_business_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56002';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_concurrency_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56004';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_conflict_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56006';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_duplicate_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56007';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_not_found_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56005';
END
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

CREATE OR REPLACE PROCEDURE sp_throw_validation_exception(
"message" TEXT = NULL
)
LANGUAGE plpgsql
AS $$
BEGIN
IF "message" IS NULL THEN
"message" := '';
END IF;

RAISE USING MESSAGE = "message", ERRCODE = '56001';
END
$$;
38 changes: 38 additions & 0 deletions src/DbEx.SqlServer/Console/MigrationArgsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

using DbEx.Migration;
using System;
using System.Linq;

namespace DbEx.SqlServer.Console
{
/// <summary>
/// Provides extension methods for <see cref="MigrationArgs"/>.
/// </summary>
public static class MigrationArgsExtensions
{
/// <summary>
/// Include the SQL Server extended <b>Schema</b> scripts (stored procedures and functions) from <see href="https://github.com/Avanade/DbEx/tree/main/src/DbEx.SqlServer/Resources/ExtendedSchema"/>.
/// </summary>
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
public static MigrationArgs IncludeExtendedSchemaScripts(this MigrationArgs args)
{
AddExtendedSchemaScripts(args);
return args;
}

/// <summary>
/// Adds the SQL Server extended <b>Schema</b> scripts (stored procedures and functions) from <see href="https://github.com/Avanade/DbEx/tree/main/src/DbEx.SqlServer/Resources/ExtendedSchema"/>.
/// </summary>
/// <typeparam name="TArgs">The <see cref="MigrationArgsBase{TSelf}"/> <see cref="Type"/>.</typeparam>
/// <param name="args">The <see cref="MigrationArgsBase{TSelf}"/>.</param>
public static void AddExtendedSchemaScripts<TArgs>(TArgs args) where TArgs : MigrationArgsBase<TArgs>
{
foreach (var rn in typeof(MigrationArgsExtensions).Assembly.GetManifestResourceNames().Where(x => x.StartsWith("DbEx.SqlServer.Resources.ExtendedSchema.") && x.EndsWith(".sql")))
{
args.AddScript(MigrationCommand.Schema, typeof(MigrationArgsExtensions).Assembly, rn);
}
}
}
}
Loading

0 comments on commit e964495

Please sign in to comment.