auto increment ID.

model tables are automatically created.
pull/6/head
kay.one 11 years ago
parent aeebae33fd
commit 7603d8e1ba

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.Configuration
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 @@ namespace NzbDrone.Core.Test.Configuration
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 @@ namespace NzbDrone.Core.Datastore
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)

@ -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…
Cancel
Save