Skip to content

Commit e964495

Browse files
authored
v2.7.0 (#61)
* 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.
1 parent 169f2d6 commit e964495

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+714
-21
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
Represents the **NuGet** versions.
44

5+
## v2.7.0
6+
- *Enhancement:* Require a means to add an explicitly named resource-based script outside of the automatic convention-based discovery; see new `MigrationArgs.AddScript`.
7+
- *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`).
8+
- *Enhancement:* Added PostgreSQL equivalent standardized SQL Server scripts (functions and stored procedures).
9+
- *Enhancement:* Added command-line option `-dso|--drop-schema-objects` to set `MigrationArgs.DropSchemaObjects` directly from the console.
10+
511
## v2.6.1
6-
- *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
12+
- *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.
713

814
## v2.6.0
915
- *Enhancement:* Added a `DbColumnSchema.SqlType2` that does _not_ include nullability.

Common.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>2.6.1</Version>
3+
<Version>2.7.0</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

src/DbEx.MySql/DbEx.MySql.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</ItemGroup>
4242

4343
<ItemGroup>
44-
<PackageReference Include="CoreEx.Database.MySql" Version="3.25.6" />
44+
<PackageReference Include="CoreEx.Database.MySql" Version="3.27.0" />
4545
<PackageReference Include="dbup-mysql" Version="5.0.44" />
4646
</ItemGroup>
4747

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
using DbEx.Migration;
4+
using System.Linq;
5+
6+
namespace DbEx.Postgres.Console
7+
{
8+
/// <summary>
9+
/// Provides extension methods for <see cref="MigrationArgs"/>.
10+
/// </summary>
11+
public static class MigrationArgsExtensions
12+
{
13+
/// <summary>
14+
/// 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"/>.
15+
/// </summary>
16+
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
17+
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
18+
public static MigrationArgs IncludeExtendedSchemaScripts(this MigrationArgs args)
19+
{
20+
AddExtendedSchemaScripts(args);
21+
return args;
22+
}
23+
24+
/// <summary>
25+
/// 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"/>.
26+
/// </summary>
27+
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
28+
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
29+
public static void AddExtendedSchemaScripts<TArgs>(TArgs args) where TArgs : MigrationArgsBase<TArgs>
30+
{
31+
foreach (var rn in typeof(MigrationArgsExtensions).Assembly.GetManifestResourceNames().Where(x => x.StartsWith("DbEx.Postgres.Resources.ExtendedSchema.") && x.EndsWith(".sql")))
32+
{
33+
args.AddScript(MigrationCommand.Schema, typeof(MigrationArgsExtensions).Assembly, rn);
34+
}
35+
}
36+
}
37+
}

src/DbEx.Postgres/DbEx.Postgres.csproj

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
<None Remove="Resources\JournalCreate.sql" />
3232
<None Remove="Resources\JournalExists.sql" />
3333
<None Remove="Resources\JournalPrevious.sql" />
34+
<None Remove="Resources\ExtendedSchema\Functions\fn_get_tenant_id.sql" />
35+
<None Remove="Resources\ExtendedSchema\Functions\fn_get_timestamp.sql" />
36+
<None Remove="Resources\ExtendedSchema\Functions\fn_get_username.sql" />
37+
<None Remove="Resources\ExtendedSchema\Functions\fn_get_user_id.sql" />
38+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_set_session_context.sql" />
39+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_authorization_exception.sql" />
40+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_business_exception.sql" />
41+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_concurrency_exception.sql" />
42+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_conflict_exception.sql" />
43+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_duplicate_exception.sql" />
44+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_not_found_exception.sql" />
45+
<None Remove="Resources\ExtendedSchema\Stored Procedures\sp_throw_validation_exception.sql" />
3446
<None Remove="Resources\ScriptAlter_sql.hbs" />
3547
<None Remove="Resources\ScriptCreate_sql.hbs" />
3648
<None Remove="Resources\ScriptDefault_sql.hbs" />
@@ -42,7 +54,7 @@
4254
</ItemGroup>
4355

4456
<ItemGroup>
45-
<PackageReference Include="CoreEx.Database.Postgres" Version="3.25.6" />
57+
<PackageReference Include="CoreEx.Database.Postgres" Version="3.27.0" />
4658
<PackageReference Include="dbup-postgresql" Version="5.0.40" />
4759
</ItemGroup>
4860

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
2+
3+
CREATE OR REPLACE FUNCTION fn_get_tenant_id(
4+
"Override" TEXT = NULL
5+
)
6+
RETURNS TEXT
7+
LANGUAGE plpgsql
8+
AS $$
9+
DECLARE "TenantId" TEXT;
10+
BEGIN
11+
IF "Override" IS NULL THEN
12+
"TenantId" := current_setting('Session.TenantId', true);
13+
ELSE
14+
"TenantId" := "Override";
15+
END IF;
16+
17+
RETURN "TenantId";
18+
END
19+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
2+
3+
CREATE OR REPLACE FUNCTION fn_get_timestamp(
4+
"Override" TIMESTAMP WITH TIME ZONE = NULL
5+
)
6+
RETURNS TIMESTAMP WITH TIME ZONE
7+
LANGUAGE plpgsql
8+
AS $$
9+
DECLARE "Timestamp" TIMESTAMP WITH TIME ZONE;
10+
BEGIN
11+
"Timestamp" := CURRENT_TIMESTAMP;
12+
IF "Override" IS NULL THEN
13+
"Timestamp" := to_timestamp(current_setting('Session.Timestamp', true), 'YYYY-MM-DD"T"HH24:MI:SS.FF6');
14+
IF "Timestamp" IS NULL THEN
15+
"Timestamp" := CURRENT_TIMESTAMP;
16+
END IF;
17+
ELSE
18+
"Timestamp" := "Override";
19+
END IF;
20+
21+
RETURN "Timestamp";
22+
END
23+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
2+
3+
CREATE OR REPLACE FUNCTION fn_get_user_id(
4+
"Override" TEXT = NULL
5+
)
6+
RETURNS TEXT
7+
LANGUAGE plpgsql
8+
AS $$
9+
DECLARE "UserId" TEXT;
10+
BEGIN
11+
IF "Override" IS NULL THEN
12+
"UserId" := current_setting('Session.UserId', true);
13+
ELSE
14+
"UserId" := "Override";
15+
END IF;
16+
17+
RETURN "UserId";
18+
END
19+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
2+
3+
CREATE OR REPLACE FUNCTION fn_get_username(
4+
"Override" TEXT = NULL
5+
)
6+
RETURNS TEXT
7+
LANGUAGE plpgsql
8+
AS $$
9+
DECLARE "Username" TEXT;
10+
BEGIN
11+
IF "Override" IS NULL THEN
12+
"Username" := current_setting('Session.Username', true);
13+
IF "Username" IS NULL THEN
14+
"Username" := current_user;
15+
END IF;
16+
ELSE
17+
"Username" := "Override";
18+
END IF;
19+
20+
RETURN "Username";
21+
END
22+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_set_session_context(
4+
"Timestamp" TIMESTAMP WITH TIME ZONE = NULL,
5+
"Username" TEXT = NULL,
6+
"TenantId" TEXT = NULL,
7+
"UserId" TEXT = NULL
8+
)
9+
LANGUAGE plpgsql
10+
AS $$
11+
BEGIN
12+
IF "Timestamp" IS NOT NULL THEN
13+
PERFORM set_config('Session.Timestamp', to_char("Timestamp", 'YYYY-MM-DD"T"HH24:MI:SS.FF6'), false);
14+
END IF;
15+
16+
IF "Username" IS NOT NULL THEN
17+
PERFORM set_config('Session.Username', "Username", false);
18+
END IF;
19+
20+
IF "TenantId" IS NOT NULL THEN
21+
PERFORM set_config('Session.TenantId', "TenantId", false);
22+
END IF;
23+
24+
IF "UserId" IS NOT NULL THEN
25+
PERFORM set_config('Session.UserId', "UserId", false);
26+
END IF;
27+
END
28+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_authorization_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56003';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_business_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56002';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_concurrency_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56004';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_conflict_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56006';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_duplicate_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56007';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_not_found_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56005';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
CREATE OR REPLACE PROCEDURE sp_throw_validation_exception(
4+
"message" TEXT = NULL
5+
)
6+
LANGUAGE plpgsql
7+
AS $$
8+
BEGIN
9+
IF "message" IS NULL THEN
10+
"message" := '';
11+
END IF;
12+
13+
RAISE USING MESSAGE = "message", ERRCODE = '56001';
14+
END
15+
$$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx
2+
3+
using DbEx.Migration;
4+
using System;
5+
using System.Linq;
6+
7+
namespace DbEx.SqlServer.Console
8+
{
9+
/// <summary>
10+
/// Provides extension methods for <see cref="MigrationArgs"/>.
11+
/// </summary>
12+
public static class MigrationArgsExtensions
13+
{
14+
/// <summary>
15+
/// 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"/>.
16+
/// </summary>
17+
/// <param name="args">The <see cref="MigrationArgs"/>.</param>
18+
/// <returns>The <see cref="MigrationArgs"/> to support fluent-style method-chaining.</returns>
19+
public static MigrationArgs IncludeExtendedSchemaScripts(this MigrationArgs args)
20+
{
21+
AddExtendedSchemaScripts(args);
22+
return args;
23+
}
24+
25+
/// <summary>
26+
/// 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"/>.
27+
/// </summary>
28+
/// <typeparam name="TArgs">The <see cref="MigrationArgsBase{TSelf}"/> <see cref="Type"/>.</typeparam>
29+
/// <param name="args">The <see cref="MigrationArgsBase{TSelf}"/>.</param>
30+
public static void AddExtendedSchemaScripts<TArgs>(TArgs args) where TArgs : MigrationArgsBase<TArgs>
31+
{
32+
foreach (var rn in typeof(MigrationArgsExtensions).Assembly.GetManifestResourceNames().Where(x => x.StartsWith("DbEx.SqlServer.Resources.ExtendedSchema.") && x.EndsWith(".sql")))
33+
{
34+
args.AddScript(MigrationCommand.Schema, typeof(MigrationArgsExtensions).Assembly, rn);
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)