mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-17 10:45:49 +02:00
auto increment ID.
model tables are automatically created.
This commit is contained in:
parent
aeebae33fd
commit
7603d8e1ba
@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.Configuration
|
|||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IConfigRepository>().Setup(c => c.All())
|
Mocker.GetMock<IConfigRepository>().Setup(c => c.All())
|
||||||
.Returns(new List<Config> { new Config { Key = "Key1", Value = "Value1" } });
|
.Returns(new List<Config> { new Config { Key = "key1", Value = "Value1" } });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ namespace NzbDrone.Core.Test.Configuration
|
|||||||
|
|
||||||
if (propertyInfo.PropertyType == typeof(string))
|
if (propertyInfo.PropertyType == typeof(string))
|
||||||
{
|
{
|
||||||
value = new Guid().ToString();
|
value = Guid.NewGuid().ToString();
|
||||||
}
|
}
|
||||||
else if (propertyInfo.PropertyType == typeof(int))
|
else if (propertyInfo.PropertyType == typeof(int))
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
|
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
|
||||||
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
|
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
|
||||||
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
|
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
|
||||||
<RunPreBuildEvents>false</RunPreBuildEvents>
|
<RunPreBuildEvents>true</RunPreBuildEvents>
|
||||||
<RunPostBuildEvents>false</RunPostBuildEvents>
|
<RunPostBuildEvents>true</RunPostBuildEvents>
|
||||||
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
|
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
|
||||||
<InstrumentAssembly>true</InstrumentAssembly>
|
<InstrumentAssembly>true</InstrumentAssembly>
|
||||||
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
|
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
|
||||||
|
@ -30,7 +30,11 @@ namespace NzbDrone.Core.Datastore
|
|||||||
|
|
||||||
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
|
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
|
||||||
var dbFactory = new OrmLiteConnectionFactory(connectionString);
|
var dbFactory = new OrmLiteConnectionFactory(connectionString);
|
||||||
return dbFactory.Open();
|
var connection = dbFactory.Open();
|
||||||
|
|
||||||
|
Migration.CreateTables(connection);
|
||||||
|
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetConnectionString(string dbPath)
|
private string GetConnectionString(string dbPath)
|
||||||
|
22
NzbDrone.Core/Datastore/Migration.cs
Normal file
22
NzbDrone.Core/Datastore/Migration.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using ServiceStack.OrmLite;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore
|
||||||
|
{
|
||||||
|
public static class Migration
|
||||||
|
{
|
||||||
|
public static void CreateTables(IDbConnection dbConnection)
|
||||||
|
{
|
||||||
|
var types = typeof(ModelBase).Assembly.GetTypes();
|
||||||
|
|
||||||
|
var models = types.Where(c => c.BaseType == typeof(ModelBase));
|
||||||
|
|
||||||
|
foreach (var model in models)
|
||||||
|
{
|
||||||
|
dbConnection.CreateTable(true, model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using ServiceStack.DataAnnotations;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Datastore
|
namespace NzbDrone.Core.Datastore
|
||||||
{
|
{
|
||||||
[DebuggerDisplay("{GetType()} ID = {Id}")]
|
[DebuggerDisplay("{GetType()} ID = {Id}")]
|
||||||
public abstract class ModelBase
|
public abstract class ModelBase
|
||||||
{
|
{
|
||||||
|
[AutoIncrement]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,7 @@
|
|||||||
<Compile Include="Constants.cs" />
|
<Compile Include="Constants.cs" />
|
||||||
<Compile Include="ContainerExtensions.cs" />
|
<Compile Include="ContainerExtensions.cs" />
|
||||||
<Compile Include="Datastore\DbFactory.cs" />
|
<Compile Include="Datastore\DbFactory.cs" />
|
||||||
|
<Compile Include="Datastore\Migration.cs" />
|
||||||
<Compile Include="Datastore\ModelBase.cs" />
|
<Compile Include="Datastore\ModelBase.cs" />
|
||||||
<Compile Include="Datastore\BasicRepository.cs" />
|
<Compile Include="Datastore\BasicRepository.cs" />
|
||||||
<Compile Include="DecisionEngine\DownloadDecision.cs" />
|
<Compile Include="DecisionEngine\DownloadDecision.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user