generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
45 changed files
with
714 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/DbEx.Postgres/Resources/ExtendedSchema/Functions/fn_get_tenant_id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
23 changes: 23 additions & 0 deletions
23
src/DbEx.Postgres/Resources/ExtendedSchema/Functions/fn_get_timestamp.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
19 changes: 19 additions & 0 deletions
19
src/DbEx.Postgres/Resources/ExtendedSchema/Functions/fn_get_user_id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
22 changes: 22 additions & 0 deletions
22
src/DbEx.Postgres/Resources/ExtendedSchema/Functions/fn_get_username.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
28 changes: 28 additions & 0 deletions
28
src/DbEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_set_session_context.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
....Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_authorization_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
src/DbEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_business_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
...Ex.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_concurrency_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
src/DbEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_conflict_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
...DbEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_duplicate_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
...DbEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_not_found_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
15 changes: 15 additions & 0 deletions
15
...bEx.Postgres/Resources/ExtendedSchema/Stored Procedures/sp_throw_validation_exception.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.