Skip to content

Commit

Permalink
Changed to use the
Browse files Browse the repository at this point in the history
Dgmjr.EntityFrameworkCore.Migrations
project
  • Loading branch information
dgmjr committed Nov 8, 2023
1 parent 9fb2cc8 commit b9eee96
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<Using Include="Dgmjr.Primitives.EntityFrameworkCore.FunctionNames" Static="true" />
<Using Include="Dgmjr.Primitives.EntityFrameworkCore.Constants" Static="true" />
<Using Include="Dgmjr.EntityFrameworkCore.Migrations" />
<Using Include="System" />
</ItemGroup>
<Import Project="../src/Dgmjr.Primitives.props" />
Expand Down
26 changes: 13 additions & 13 deletions EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives", "..\src\Dgmjr.Primitives.csproj", "{4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives.EntityFrameworkCore", "Dgmjr.Primitives.EntityFrameworkCore.csproj", "{E7E23589-B331-4475-B0D3-9645F65D9CCC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives.EntityFrameworkCore", "Dgmjr.Primitives.EntityFrameworkCore.csproj", "{5B975267-5DCE-419A-AC37-F9215357106C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -34,18 +34,18 @@ Global
{4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Production|Any CPU.Build.0 = Local|Any CPU
{4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Release|Any CPU.Build.0 = Release|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Local|Any CPU.ActiveCfg = Local|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Local|Any CPU.Build.0 = Local|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Testing|Any CPU.Build.0 = Testing|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Staging|Any CPU.Build.0 = Staging|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Production|Any CPU.ActiveCfg = Local|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Production|Any CPU.Build.0 = Local|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7E23589-B331-4475-B0D3-9645F65D9CCC}.Release|Any CPU.Build.0 = Release|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Local|Any CPU.ActiveCfg = Local|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Local|Any CPU.Build.0 = Local|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Testing|Any CPU.Build.0 = Testing|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Staging|Any CPU.Build.0 = Staging|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Production|Any CPU.ActiveCfg = Local|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Production|Any CPU.Build.0 = Local|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B975267-5DCE-419A-AC37-F9215357106C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 8 additions & 6 deletions EntityFrameworkCore/EmailAddressEfCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ public static MigrationBuilder HasIsValidEmailAddressFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.ReadAssemblyResourceAllText(IsValidEmailAddress + _sql)
.Replace("{schema}", schema)
.Replace("{functionName}", functionName)
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidEmailAddress + _sql)
)
);
return migrationBuilder;
}
Expand All @@ -102,7 +104,7 @@ public static MigrationBuilder RollBackIsValidEmailAddressFunction(
string functionName
)
{
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]");
migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName));
return migrationBuilder;
}

Expand Down
21 changes: 12 additions & 9 deletions EntityFrameworkCore/ObjectIdEfCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ public static MigrationBuilder HasIsValidObjectIdFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.GetManifestResourceStream(ufn_ + "IsValidObjectId.sql")
.ReadToEnd()
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidObjectId + _sql)
)
);
return migrationBuilder;
}

public static MigrationBuilder RollBackIsValidObjectIdFunction(
this MigrationBuilder migrationBuilder
) => migrationBuilder.RollBackIsValidObjectIdFunction(ufn_ + "IsValidObjectId");
) => migrationBuilder.RollBackIsValidObjectIdFunction(IsValidObjectId);

public static MigrationBuilder RollBackIsValidObjectIdFunction(
this MigrationBuilder migrationBuilder,
Expand All @@ -72,15 +75,15 @@ public static MigrationBuilder RollBackIsValidObjectIdFunction(
string functionName
)
{
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}];");
migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName));
return migrationBuilder;
}

#if NET7_0_OR_GREATER
public static Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder HasObjectIdCheckConstraint(
this Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder tableBuilder,
public static TableBuilder HasObjectIdCheckConstraint(
this TableBuilder tableBuilder,
string columnName,
string functionName = "IsValidObjectId",
string functionName = IsValidObjectId,
string schema = DboSchema.ShortName
)
{
Expand Down
12 changes: 7 additions & 5 deletions EntityFrameworkCore/PhoneNumberEfCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ public static MigrationBuilder HasIsValidPhoneNumberFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.ReadAssemblyResourceAllText(IsValidPhoneNumber + _sql)
.Replace("{schema}", schema)
.Replace("{functionName}", functionName)
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidPhoneNumber + _sql)
)
);
return migrationBuilder;
}
Expand Down
2 changes: 1 addition & 1 deletion EntityFrameworkCore/Resources/ufn_IsUri.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RETURN CASE
WHEN @uri LIKE '%:%' THEN 1
WHEN @value LIKE '%:%' THEN 1
ELSE 0
END
2 changes: 1 addition & 1 deletion EntityFrameworkCore/Resources/ufn_IsUrl.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RETURN
CASE WHEN @url LIKE '%://%'
CASE WHEN @value LIKE '%://%'
-- OR @url LIKE 'http://%'
-- OR @url LIKE 'ftp://%'
-- OR @url LIKE 'tg://%'
Expand Down
2 changes: 1 addition & 1 deletion EntityFrameworkCore/Resources/ufn_IsUrn.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RETURN CASE WHEN @urn LIKE 'urn:%' THEN 1 ELSE 0 END
RETURN CASE WHEN @value LIKE 'urn:%' THEN 1 ELSE 0 END
4 changes: 2 additions & 2 deletions EntityFrameworkCore/Resources/ufn_IsValidEmailAddress.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DECLARE @bitEmailVal as Bit
DECLARE @EmailText nvarchar(MAX) = @EMAIL
DECLARE @EmailText nvarchar(MAX) = @value

SET @EmailText=ltrim(rtrim(isnull(@EMAIL,'')))
SET @EmailText=ltrim(rtrim(isnull(@value,'')))

SET @bitEmailVal = case when @EmailText = '' then 0
when @EmailText like '% %' then 0
Expand Down
2 changes: 1 addition & 1 deletion EntityFrameworkCore/Resources/ufn_IsValidObjectId.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RETURN CASE
WHEN @objectId LIKE '[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
WHEN @value LIKE '[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
THEN 1
ELSE 0
END
18 changes: 9 additions & 9 deletions EntityFrameworkCore/Resources/ufn_IsValidPhoneNumber.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
RETURN CASE
WHEN @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
WHEN @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
THEN 1 ELSE 0
END
16 changes: 10 additions & 6 deletions EntityFrameworkCore/UriEfCoreExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Dgmjr.EntityFrameworkCore.Migrations;

namespace Dgmjr.Primitives.EntityFrameworkCore;

public static class UriEfCoreExtensions
Expand Down Expand Up @@ -33,11 +35,13 @@ public static MigrationBuilder HasIsValidUriFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.ReadAssemblyResourceAllText(IsUri + _sql)
.Replace("{schema}", schema)
.Replace("{functionName}", functionName)
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUri + _sql)
)
);
return migrationBuilder;
}
Expand All @@ -57,7 +61,7 @@ public static MigrationBuilder RollBackIsValidUriFunction(
string functionName
)
{
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]");
migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName));
return migrationBuilder;
}

Expand Down
14 changes: 8 additions & 6 deletions EntityFrameworkCore/UrlEfCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public static MigrationBuilder HasIsValidUrlFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.ReadAssemblyResourceAllText(IsUrl + _sql)
.Replace("{schema}", schema)
.Replace("{functionName}", functionName)
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUrl + _sql)
)
);
return migrationBuilder;
}
Expand All @@ -56,7 +58,7 @@ public static MigrationBuilder RollBackIsValidUrlFunction(
string functionName
)
{
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]");
migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName));
return migrationBuilder;
}

Expand Down
14 changes: 8 additions & 6 deletions EntityFrameworkCore/UrnEfCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public static MigrationBuilder HasIsValidUrnFunction(
string functionName
)
{
migrationBuilder.Sql(
typeof(Constants).Assembly
.ReadAssemblyResourceAllText(IsUrn + _sql)
.Replace("{schema}", schema)
.Replace("{functionName}", functionName)
migrationBuilder.Operations.Add(
new CreateFunctionOperation(
schema,
functionName,
"@value nvarchar(MAX)",
typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUrn + _sql)
)
);
return migrationBuilder;
}
Expand All @@ -70,7 +72,7 @@ public static MigrationBuilder RollBackIsValidUrnFunction(
string functionName
)
{
migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]");
migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName));
return migrationBuilder;
}

Expand Down

0 comments on commit b9eee96

Please sign in to comment.