Skip to content

Commit 522178a

Browse files
committed
Refactor BaGet's database providers
1 parent 5fcebb5 commit 522178a

33 files changed

+177
-71
lines changed

BaGet.sln

+21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3232
EndProject
3333
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Core.Server", "src\BaGet.Core.Server\BaGet.Core.Server.csproj", "{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}"
3434
EndProject
35+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Database.Sqlite", "src\BaGet.Database.Sqlite\BaGet.Database.Sqlite.csproj", "{EC5E6B2C-2494-40E8-8682-080BA580DDA7}"
36+
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Database.SqlServer", "src\BaGet.Database.SqlServer\BaGet.Database.SqlServer.csproj", "{4C513AFC-BA7B-471D-B8F6-268E7AD2074C}"
38+
EndProject
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Database.MySql", "src\BaGet.Database.MySql\BaGet.Database.MySql.csproj", "{A4375529-E855-4D46-AA4F-B3FE630C3DE1}"
40+
EndProject
3541
Global
3642
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3743
Debug|Any CPU = Debug|Any CPU
@@ -78,6 +84,18 @@ Global
7884
{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
7985
{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
8086
{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}.Release|Any CPU.Build.0 = Release|Any CPU
87+
{EC5E6B2C-2494-40E8-8682-080BA580DDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
88+
{EC5E6B2C-2494-40E8-8682-080BA580DDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
89+
{EC5E6B2C-2494-40E8-8682-080BA580DDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
90+
{EC5E6B2C-2494-40E8-8682-080BA580DDA7}.Release|Any CPU.Build.0 = Release|Any CPU
91+
{4C513AFC-BA7B-471D-B8F6-268E7AD2074C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
92+
{4C513AFC-BA7B-471D-B8F6-268E7AD2074C}.Debug|Any CPU.Build.0 = Debug|Any CPU
93+
{4C513AFC-BA7B-471D-B8F6-268E7AD2074C}.Release|Any CPU.ActiveCfg = Release|Any CPU
94+
{4C513AFC-BA7B-471D-B8F6-268E7AD2074C}.Release|Any CPU.Build.0 = Release|Any CPU
95+
{A4375529-E855-4D46-AA4F-B3FE630C3DE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96+
{A4375529-E855-4D46-AA4F-B3FE630C3DE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
97+
{A4375529-E855-4D46-AA4F-B3FE630C3DE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
98+
{A4375529-E855-4D46-AA4F-B3FE630C3DE1}.Release|Any CPU.Build.0 = Release|Any CPU
8199
EndGlobalSection
82100
GlobalSection(SolutionProperties) = preSolution
83101
HideSolutionNode = FALSE
@@ -93,6 +111,9 @@ Global
93111
{AC764A9A-9EAF-422B-9223-D3290C3CFD79} = {C237857D-AD8E-4C52-974F-6A8155BB0C18}
94112
{D067D82E-D515-44D1-A832-C79F29418DFC} = {26A0B557-53FB-4B9A-94C4-BCCF1BDCB0CC}
95113
{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C} = {26A0B557-53FB-4B9A-94C4-BCCF1BDCB0CC}
114+
{EC5E6B2C-2494-40E8-8682-080BA580DDA7} = {26A0B557-53FB-4B9A-94C4-BCCF1BDCB0CC}
115+
{4C513AFC-BA7B-471D-B8F6-268E7AD2074C} = {26A0B557-53FB-4B9A-94C4-BCCF1BDCB0CC}
116+
{A4375529-E855-4D46-AA4F-B3FE630C3DE1} = {26A0B557-53FB-4B9A-94C4-BCCF1BDCB0CC}
96117
EndGlobalSection
97118
GlobalSection(ExtensibilityGlobals) = postSolution
98119
SolutionGuid = {1423C027-2C90-417F-8629-2A4CF107C055}

src/BaGet/Entities/AbstractContext.cs src/BaGet.Core/Entities/AbstractContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System.Threading.Tasks;
2-
using BaGet.Core.Entities;
32
using Microsoft.EntityFrameworkCore;
43
using Microsoft.EntityFrameworkCore.Metadata.Builders;
54

6-
namespace BaGet.Entities
5+
namespace BaGet.Core.Entities
76
{
87
public abstract class AbstractContext<TContext> : DbContext, IContext where TContext : DbContext
98
{

src/BaGet/Entities/Converters/StringArrayToJsonConverter.cs src/BaGet.Core/Entities/Converters/StringArrayToJsonConverter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
1+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
22
using Newtonsoft.Json;
33

4-
namespace BaGet.Entities
4+
namespace BaGet.Core.Entities
55
{
66
public class StringArrayToJsonConverter : ValueConverter<string[], string>
77
{
88
public static readonly StringArrayToJsonConverter Instance = new StringArrayToJsonConverter();
99

1010
public StringArrayToJsonConverter()
1111
: base(
12-
v => JsonConvert.SerializeObject(v),
13-
v => (!string.IsNullOrEmpty(v)) ? JsonConvert.DeserializeObject<string[]>(v) : new string[0])
12+
v => JsonConvert.SerializeObject(v),
13+
v => (!string.IsNullOrEmpty(v)) ? JsonConvert.DeserializeObject<string[]>(v) : new string[0])
1414
{
1515
}
1616
}

src/BaGet/Entities/Converters/UriToStringConverter.cs src/BaGet.Core/Entities/Converters/UriToStringConverter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using System;
1+
using System;
22
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
33

4-
namespace BaGet.Entities
4+
namespace BaGet.Core.Entities
55
{
66
public class UriToStringConverter : ValueConverter<Uri, string>
77
{
88
public static readonly UriToStringConverter Instance = new UriToStringConverter();
99

1010
public UriToStringConverter()
1111
: base(
12-
v => v.AbsoluteUri,
13-
v => new Uri(v))
12+
v => v.AbsoluteUri,
13+
v => new Uri(v))
1414
{
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\BaGet.Core\BaGet.Core.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Folder Include="Migrations\" />
17+
</ItemGroup>
18+
19+
</Project>
20+

src/BaGet/Migrations/MySql/20181212113156_Initial.Designer.cs src/BaGet.Database.MySql/Migrations/20181212113156_Initial.Designer.cs

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/MySql/20181212113156_Initial.cs src/BaGet.Database.MySql/Migrations/20181212113156_Initial.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.EntityFrameworkCore.Metadata;
33
using Microsoft.EntityFrameworkCore.Migrations;
44

5-
namespace BaGet.Migrations.MySql
5+
namespace BaGet.Database.MySql.Migrations
66
{
77
public partial class Initial : Migration
88
{

src/BaGet/Migrations/MySql/20190303071640_AddSearchDimensions.Designer.cs src/BaGet.Database.MySql/Migrations/20190303071640_AddSearchDimensions.Designer.cs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/MySql/20190303071640_AddSearchDimensions.cs src/BaGet.Database.MySql/Migrations/20190303071640_AddSearchDimensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
1+
using System;
22
using Microsoft.EntityFrameworkCore.Metadata;
33
using Microsoft.EntityFrameworkCore.Migrations;
44

5-
namespace BaGet.Migrations.Mysql
5+
namespace BaGet.Database.MySql.Migrations
66
{
77
public partial class AddSearchDimensions : Migration
88
{

src/BaGet/Migrations/MySql/MySqlContextModelSnapshot.cs src/BaGet.Database.MySql/Migrations/MySqlContextModelSnapshot.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// <auto-generated />
1+
// <auto-generated />
22
using System;
3-
using BaGet.Entities;
43
using Microsoft.EntityFrameworkCore;
54
using Microsoft.EntityFrameworkCore.Infrastructure;
65
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
76

8-
namespace BaGet.Migrations.MySql
7+
namespace BaGet.Database.MySql.Migrations
98
{
109
[DbContext(typeof(MySqlContext))]
1110
partial class MySqlContextModelSnapshot : ModelSnapshot

src/BaGet/Entities/MySqlContext.cs src/BaGet.Database.MySql/MySqlContext.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using BaGet.Core.Entities;
12
using Microsoft.EntityFrameworkCore;
23
using MySql.Data.MySqlClient;
34

4-
namespace BaGet.Entities
5+
namespace BaGet.Database.MySql
56
{
67
public class MySqlContext : AbstractContext<MySqlContext>
78
{

src/BaGet.Database.MySql/readme.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# BaGet's MySQL Database Provider
2+
3+
This project contains BaGet's MySQL database provider.
4+
5+
## Migrations
6+
7+
Regenerate migrations with:
8+
9+
```
10+
dotnet ef migrations add MigrationName --context MySqlContext --output-dir Migrations --startup-project ..\BaGet\BaGet.csproj
11+
12+
dotnet ef database update --context MySqlContext
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\BaGet.Core\BaGet.Core.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Folder Include="Migrations\" />
17+
</ItemGroup>
18+
19+
</Project>

src/BaGet/Migrations/SqlServer/20180804082816_Initial.Designer.cs src/BaGet.Database.SqlServer/Migrations/20180804082816_Initial.Designer.cs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/SqlServer/20180804082816_Initial.cs src/BaGet.Database.SqlServer/Migrations/20180804082816_Initial.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
1+
using System;
22
using Microsoft.EntityFrameworkCore.Metadata;
33
using Microsoft.EntityFrameworkCore.Migrations;
44

5-
namespace BaGet.Migrations.SqlServer
5+
namespace BaGet.Database.SqlServer.Migrations
66
{
77
public partial class Initial : Migration
88
{

src/BaGet/Migrations/SqlServer/20190303071621_AddSearchDimensions.Designer.cs src/BaGet.Database.SqlServer/Migrations/20190303071621_AddSearchDimensions.Designer.cs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/SqlServer/20190303071621_AddSearchDimensions.cs src/BaGet.Database.SqlServer/Migrations/20190303071621_AddSearchDimensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Microsoft.EntityFrameworkCore.Metadata;
1+
using Microsoft.EntityFrameworkCore.Metadata;
22
using Microsoft.EntityFrameworkCore.Migrations;
33

4-
namespace BaGet.Migrations.SqlServer
4+
namespace BaGet.Database.SqlServer.Migrations
55
{
66
public partial class AddSearchDimensions : Migration
77
{

src/BaGet/Migrations/SqlServer/SqlServerContextModelSnapshot.cs src/BaGet.Database.SqlServer/Migrations/SqlServerContextModelSnapshot.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// <auto-generated />
1+
// <auto-generated />
22
using System;
3-
using BaGet.Entities;
43
using Microsoft.EntityFrameworkCore;
54
using Microsoft.EntityFrameworkCore.Infrastructure;
65
using Microsoft.EntityFrameworkCore.Metadata;
76
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
87

9-
namespace BaGet.Migrations.SqlServer
8+
namespace BaGet.Database.SqlServer.Migrations
109
{
1110
[DbContext(typeof(SqlServerContext))]
1211
partial class SqlServerContextModelSnapshot : ModelSnapshot

src/BaGet/Entities/SqlServerContext.cs src/BaGet.Database.SqlServer/SqlServerContext.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Data.SqlClient;
1+
using System.Data.SqlClient;
22
using System.Linq;
3+
using BaGet.Core.Entities;
34
using Microsoft.EntityFrameworkCore;
45

5-
namespace BaGet.Entities
6+
namespace BaGet.Database.SqlServer
67
{
78
public class SqlServerContext : AbstractContext<SqlServerContext>
89
{
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# BaGet's SQL Server Database Provider
2+
3+
This project contains BaGet's Microsoft SQL Server database provider.
4+
5+
## Migrations
6+
7+
Regenerate migrations with:
8+
9+
```
10+
dotnet ef migrations add MigrationName --context SqlServerContext --output-dir Migrations --startup-project ..\BaGet\BaGet.csproj
11+
12+
dotnet ef database update --context SqlServerContext
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\BaGet.Core\BaGet.Core.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

src/BaGet/Migrations/Sqlite/20180804082808_Initial.Designer.cs src/BaGet.Database.Sqlite/Migrations/20180804082808_Initial.Designer.cs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/Sqlite/20180804082808_Initial.cs src/BaGet.Database.Sqlite/Migrations/20180804082808_Initial.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using System;
22
using Microsoft.EntityFrameworkCore.Migrations;
33

4-
namespace BaGet.Migrations.Sqlite
4+
namespace BaGet.Database.Sqlite
55
{
66
public partial class Initial : Migration
77
{

src/BaGet/Migrations/Sqlite/20190303072658_AddSearchDimensions.Designer.cs src/BaGet.Database.Sqlite/Migrations/20190303072658_AddSearchDimensions.Designer.cs

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet/Migrations/Sqlite/20190303072658_AddSearchDimensions.cs src/BaGet.Database.Sqlite/Migrations/20190303072658_AddSearchDimensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Microsoft.EntityFrameworkCore.Migrations;
1+
using Microsoft.EntityFrameworkCore.Migrations;
22

3-
namespace BaGet.Migrations.Sqlite
3+
namespace BaGet.Database.Sqlite.Migrations
44
{
55
public partial class AddSearchDimensions : Migration
66
{

src/BaGet/Migrations/Sqlite/SqliteContextModelSnapshot.cs src/BaGet.Database.Sqlite/Migrations/SqliteContextModelSnapshot.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// <auto-generated />
22
using System;
3-
using BaGet.Entities;
3+
using BaGet.Database.Sqlite;
44
using Microsoft.EntityFrameworkCore;
55
using Microsoft.EntityFrameworkCore.Infrastructure;
66
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
77

8-
namespace BaGet.Migrations.Sqlite
8+
namespace BaGet.Database.Sqlite.Migrations
99
{
1010
[DbContext(typeof(SqliteContext))]
1111
partial class SqliteContextModelSnapshot : ModelSnapshot

0 commit comments

Comments
 (0)