mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-12 11:15:43 +02:00
auto increment ID.
model tables are automatically created.
This commit is contained in:
parent
aeebae33fd
commit
7603d8e1ba
@ -16,7 +16,7 @@ public class ConfigCachingFixture : CoreTest<ConfigService>
|
||||
public void Setup()
|
||||
{
|
||||
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 @@ public void config_properties_should_write_and_read_using_same_key()
|
||||
|
||||
if (propertyInfo.PropertyType == typeof(string))
|
||||
{
|
||||
value = new Guid().ToString();
|
||||
value = Guid.NewGuid().ToString();
|
||||
}
|
||||
else if (propertyInfo.PropertyType == typeof(int))
|
||||
{
|
||||
|
@ -5,8 +5,8 @@
|
||||
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
|
||||
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
|
||||
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
|
||||
<RunPreBuildEvents>false</RunPreBuildEvents>
|
||||
<RunPostBuildEvents>false</RunPostBuildEvents>
|
||||
<RunPreBuildEvents>true</RunPreBuildEvents>
|
||||
<RunPostBuildEvents>true</RunPostBuildEvents>
|
||||
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
|
||||
<InstrumentAssembly>true</InstrumentAssembly>
|
||||
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
|
||||
|
@ -6,7 +6,7 @@ namespace NzbDrone.Core.Configuration
|
||||
public class Config : ModelBase
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
@ -30,7 +30,11 @@ public IDbConnection Create(string dbPath = null)
|
||||
|
||||
OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider();
|
||||
var dbFactory = new OrmLiteConnectionFactory(connectionString);
|
||||
return dbFactory.Open();
|
||||
var connection = dbFactory.Open();
|
||||
|
||||
Migration.CreateTables(connection);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
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 ServiceStack.DataAnnotations;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
[DebuggerDisplay("{GetType()} ID = {Id}")]
|
||||
public abstract class ModelBase
|
||||
{
|
||||
[AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,7 @@
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="ContainerExtensions.cs" />
|
||||
<Compile Include="Datastore\DbFactory.cs" />
|
||||
<Compile Include="Datastore\Migration.cs" />
|
||||
<Compile Include="Datastore\ModelBase.cs" />
|
||||
<Compile Include="Datastore\BasicRepository.cs" />
|
||||
<Compile Include="DecisionEngine\DownloadDecision.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user