Skip to content
Snippets Groups Projects
Commit 647eebc4 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Hotfix/1360-databaseScaffolding' into 'master'

Hotfix/1360 database scaffolding

See merge request !119
parents de012a32 06b84ab8
No related branches found
No related tags found
2 merge requests!124Update product with master,!119Hotfix/1360 database scaffolding
Showing
with 51 additions and 10 deletions
......@@ -22,21 +22,25 @@ migrate:
- dotnet tool install dotnet-ef; echo "1"
- dotnet tool update dotnet-ef
# Create new database and migrate to latest state
- dotnet build src\Database.Actions
- .\src\Database.Actions\bin\Debug\net5.0\Coscine.Database.Actions.exe --action-create --name $DB_NAME --source $DB_DATA_SOURCE --user $DB_USER_ID --pw $DB_PASSWORD
- dotnet run -p .\src\Database.Actions -- --action-create --name $DB_NAME --source $DB_DATA_SOURCE --user $DB_USER_ID --pw $DB_PASSWORD
# Scaffold created database
- dotnet ef dbcontext scaffold "Data Source=$DB_DATA_SOURCE;Integrated Security=False;User ID=$DB_USER_ID;Password=$DB_PASSWORD;Database=$DB_NAME" Microsoft.EntityFrameworkCore.SqlServer -o DataModel -c "Model" -f --no-onconfiguring --project "src\Database"
- dotnet ef dbcontext scaffold "Data Source=$DB_DATA_SOURCE;Integrated Security=False;User ID=$DB_USER_ID;Password=$DB_PASSWORD;Database=$DB_NAME" Microsoft.EntityFrameworkCore.SqlServer -o DataModel -c "Model" -f --no-onconfiguring --project "src\Scaffolding"
# Remove the hardcoded Connection String inside \DataModel\Model.cs
- Set-Content -Path ".\src\Database\DataModel\Model.txt" -Value (Get-Content -Path ".\src\Database\DataModel\Model.cs" | where { $_ | Select-String -Pattern '#warning' -NotMatch } | where { $_ | Select-String -Pattern 'Data Source=' -NotMatch } ) -Force
- Set-Content -Path ".\src\Database\DataModel\Model.cs" -Value (Get-Content -Path ".\src\Database\DataModel\Model.txt") -Force
- Remove-Item ".\src\Database\DataModel\Model.txt"
- Set-Content -Path ".\src\Scaffolding\DataModel\Model.txt" -Value (Get-Content -Path ".\src\Scaffolding\DataModel\Model.cs" | where { $_ | Select-String -Pattern '#warning' -NotMatch } | where { $_ | Select-String -Pattern 'Data Source=' -NotMatch } ) -Force
- Set-Content -Path ".\src\Scaffolding\DataModel\Model.cs" -Value (Get-Content -Path ".\src\Scaffolding\DataModel\Model.txt") -Force
- Remove-Item ".\src\Scaffolding\DataModel\Model.txt"
artifacts:
paths:
- src\Scaffolding\DataModel
expire_in: 1 week
cleanup:
stage: cleanup
extends: .dotnet-windows-base
script:
# Drop created database
- .\dist\Database.Actions\Coscine.Database.Actions.exe --action-drop --name $DB_NAME --source $DB_DATA_SOURCE --user $DB_USER_ID --pw $DB_PASSWORD
- dotnet run -p .\src\Database.Actions -- --action-drop --name $DB_NAME --source $DB_DATA_SOURCE --user $DB_USER_ID --pw $DB_PASSWORD
when: always
build-branch:
......
......@@ -14,7 +14,7 @@
<PackageReference Include="Coscine.Database.Helpers" Version="2.*-*" />
<PackageReference Include="Coscine.Migrations" Version="2.*-*" />
<PackageReference Include="linq2db" Version="3.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
......
......@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database", "Database\Databa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database.Tests", "Database.Tests\Database.Tests.csproj", "{2A5D0EC8-E487-4B43-A311-05852464ED01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Database.Actions", "Database.Actions\Database.Actions.csproj", "{CEFF114C-1102-43F5-9CD3-3352F18D67A4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database.Actions", "Database.Actions\Database.Actions.csproj", "{CEFF114C-1102-43F5-9CD3-3352F18D67A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scaffolding", "Scaffolding\Scaffolding.csproj", "{A2A4CB04-C609-49EB-9795-829A6210711D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -27,6 +29,10 @@ Global
{CEFF114C-1102-43F5-9CD3-3352F18D67A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEFF114C-1102-43F5-9CD3-3352F18D67A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEFF114C-1102-43F5-9CD3-3352F18D67A4}.Release|Any CPU.Build.0 = Release|Any CPU
{A2A4CB04-C609-49EB-9795-829A6210711D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2A4CB04-C609-49EB-9795-829A6210711D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2A4CB04-C609-49EB-9795-829A6210711D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2A4CB04-C609-49EB-9795-829A6210711D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Coscine.Database</RootNamespace>
......@@ -23,6 +23,11 @@
<None Include="Coscine.Database.Key.snk" />
<Reference Include="System.Web" Condition="'$(TargetFramework)' == 'net461'" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Scaffolding\DataModel\*.*">
<Link>DataModel\%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Coscine.Configuration" Version="2.*-*" />
<PackageReference Include="LinqKit" Version="1.1.23" />
......
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.DependencyInjection;
namespace Coscine.Database
{
public class CustomDesignTimeService : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
=> serviceCollection.AddSingleton<IPluralizer, CustomPluralizer>();
}
public class CustomPluralizer : IPluralizer
{
Inflector.Inflector _inflector = new Inflector.Inflector(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
public string Pluralize(string identifier)
{
return _inflector.Pluralize(identifier) ?? identifier;
}
public string Singularize(string identifier)
{
return _inflector.Singularize(identifier) ?? identifier;
}
}
}
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment