Replaced MigSharp with MigrationsDotNet

This commit is contained in:
kay.one 2011-06-16 23:58:50 -07:00
parent 63023d447d
commit 46ec4fa3ba
11 changed files with 148 additions and 1503 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -166,6 +166,11 @@ namespace Migrator.Providers
public virtual string Default(object defaultValue) public virtual string Default(object defaultValue)
{ {
if (defaultValue is String && defaultValue == String.Empty)
{
defaultValue = "''";
}
return String.Format("DEFAULT {0}", defaultValue); return String.Format("DEFAULT {0}", defaultValue);
} }
@ -174,7 +179,14 @@ namespace Migrator.Providers
ColumnPropertiesMapper mapper = GetColumnMapper(column); ColumnPropertiesMapper mapper = GetColumnMapper(column);
mapper.MapColumnProperties(column); mapper.MapColumnProperties(column);
if (column.DefaultValue != null) if (column.DefaultValue != null)
{
if (column.DefaultValue is String && column.DefaultValue.ToString() == string.Empty)
{
column.DefaultValue = @"''";
}
mapper.Default = column.DefaultValue; mapper.Default = column.DefaultValue;
}
return mapper; return mapper;
} }
} }

View File

@ -21,6 +21,7 @@
<Item>unsafe</Item> <Item>unsafe</Item>
<Item>volatile</Item> <Item>volatile</Item>
</MODIFIERS_ORDER> </MODIFIERS_ORDER>
<WRAP_LIMIT>140</WRAP_LIMIT>
</FormatSettings> </FormatSettings>
<UsingsSettings /> <UsingsSettings />
<Naming2> <Naming2>

View File

@ -74,8 +74,6 @@ namespace NzbDrone.Core.Test.Framework
var connectionString = Connection.GetConnectionString(fileName); var connectionString = Connection.GetConnectionString(fileName);
MigrationsHelper.MigrateDatabase(connectionString);
var database = Connection.GetPetaPocoDb(connectionString); var database = Connection.GetPetaPocoDb(connectionString);
return database; return database;

View File

@ -59,6 +59,8 @@ namespace NzbDrone.Core.Datastore
public static IDatabase GetPetaPocoDb(string connectionString) public static IDatabase GetPetaPocoDb(string connectionString)
{ {
MigrationsHelper.Run(connectionString, true);
var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString)); var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString));
Database.Mapper = new CustomeMapper(); Database.Mapper = new CustomeMapper();

View File

@ -1,69 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Migrator.Framework;
namespace NzbDrone.Core.Datastore.Migrations.Legacy
{
[Migration(20110523)]
public class Migration20110523 : Migration
{
public override void Up()
{
Database.RemoveTable(RepositoryProvider.JobsSchema.Name);
}
public override void Down()
{
throw new NotImplementedException();
}
}
[Migration(20110603)]
public class Migration20110603 : Migration
{
public override void Up()
{
Database.RemoveTable("Seasons");
MigrationsHelper.RemoveDeletedColumns(Database);
MigrationsHelper.AddNewColumns(Database);
}
public override void Down()
{
throw new NotImplementedException();
}
}
[Migration(20110604)]
public class Migration20110604 : Migration
{
public override void Up()
{
MigrationsHelper.ForceSubSonicMigration(Connection.CreateSimpleRepository(Connection.MainConnectionString));
var episodesTable = RepositoryProvider.EpisodesSchema;
//Database.AddIndex("idx_episodes_series_season_episode", episodesTable.Name, true,
// episodesTable.GetColumnByPropertyName("SeriesId").Name,
// episodesTable.GetColumnByPropertyName("SeasonNumber").Name,
// episodesTable.GetColumnByPropertyName("EpisodeNumber").Name);
Database.AddIndex("idx_episodes_series_season", episodesTable.Name, false,
episodesTable.GetColumnByPropertyName("SeriesId").Name,
episodesTable.GetColumnByPropertyName("SeasonNumber").Name);
Database.AddIndex("idx_episodes_series", episodesTable.Name, false,
episodesTable.GetColumnByPropertyName("SeriesId").Name);
MigrationsHelper.RemoveDeletedColumns(Database);
MigrationsHelper.AddNewColumns(Database);
}
public override void Down()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,112 @@
using System;
using System.Data;
using Migrator.Framework;
namespace NzbDrone.Core.Datastore.Migrations
{
[Migration(20110523)]
public class Migration20110523 : Migration
{
public override void Up()
{
Database.RemoveTable(RepositoryProvider.JobsSchema.Name);
}
public override void Down()
{
throw new NotImplementedException();
}
}
[Migration(20110603)]
public class Migration20110603 : Migration
{
public override void Up()
{
Database.RemoveTable("Seasons");
}
public override void Down()
{
throw new NotImplementedException();
}
}
[Migration(20110604)]
public class Migration20110616 : Migration
{
public override void Up()
{
Database.AddTable("Series", "SQLite", new[]
{
new Column("SeriesId", DbType.Int32, ColumnProperty.PrimaryKey),
new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("CleanTitle", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Status", DbType.String, ColumnProperty.Null),
new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("AirsDayOfWeek", DbType.Int16, ColumnProperty.Null),
new Column("AirTimes", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Language", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Path", DbType.String, ColumnProperty.NotNull),
new Column("Monitored", DbType.Boolean, ColumnProperty.NotNull),
new Column("QualityProfileId", DbType.Int16, ColumnProperty.NotNull),
new Column("SeasonFolder", DbType.Boolean, ColumnProperty.NotNull),
new Column("LastInfoSync", DbType.DateTime, ColumnProperty.Null),
new Column("LastDiskSync", DbType.DateTime, ColumnProperty.Null),
});
Database.AddTable("Episodes", "SQLite", new[]
{
new Column("EpisodeId", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
new Column("TvDbEpisodeId", DbType.Int32, ColumnProperty.Null),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull),
new Column("EpisodeNumber", DbType.Int16, ColumnProperty.NotNull),
new Column("Title", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Overview", DbType.String, ColumnProperty.NotNull, String.Empty),
new Column("Ignored", DbType.Boolean, ColumnProperty.NotNull, false),
new Column("EpisodeFileId", DbType.Int32, ColumnProperty.Null),
new Column("AirDate", DbType.DateTime, ColumnProperty.Null),
new Column("GrabDate", DbType.DateTime, ColumnProperty.Null),
});
Database.AddTable("EpisodeFiles", "SQLite", new[]
{
new Column("EpisodeFileId", DbType.Int32,
ColumnProperty.PrimaryKeyWithIdentity),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("Path", DbType.String, ColumnProperty.NotNull),
new Column("Quality", DbType.Int16, ColumnProperty.NotNull),
new Column("Proper", DbType.Int16, ColumnProperty.NotNull),
new Column("Size", DbType.Int64, ColumnProperty.NotNull),
new Column("DateAdded", DbType.DateTime, ColumnProperty.NotNull),
new Column("SeasonNumber", DbType.Int16, ColumnProperty.NotNull)
});
Database.AddTable("Config", "SQLite", new[]
{
new Column("Key", DbType.String, ColumnProperty.PrimaryKey),
new Column("Value", DbType.String, ColumnProperty.NotNull),
});
Database.AddTable("EpisodeFiles", "SQLite", new[]
{
new Column("HistoryId", DbType.Int64, ColumnProperty.NotNull),
new Column("EpisodeId", DbType.Int32, ColumnProperty.NotNull),
new Column("SeriesId", DbType.Int32, ColumnProperty.NotNull),
new Column("NzbTitle", DbType.String, ColumnProperty.NotNull),
new Column("Date", DbType.DateTime, ColumnProperty.NotNull),
new Column("Quality", DbType.Int16, ColumnProperty.NotNull),
new Column("IsProper", DbType.Boolean, ColumnProperty.NotNull),
new Column("Indexer", DbType.String, ColumnProperty.NotNull)
});
}
public override void Down()
{
throw new NotImplementedException();
}
}
}

View File

@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using MigSharp;
namespace NzbDrone.Core.Datastore.Migrations
{
[MigrationExport]
internal class Migration1 : IMigration
{
public void Up(IDatabase db)
{
db.CreateTable("Series")
.WithPrimaryKeyColumn("SeriesId", DbType.Int32).AsIdentity()
.WithNullableColumn("Title", DbType.String)
.WithNullableColumn("CleanTitle", DbType.String)
.WithNullableColumn("Status", DbType.String)
.WithNullableColumn("Overview", DbType.String)
.WithNullableColumn("AirsDayOfWeek", DbType.Int16)
.WithNullableColumn("AirTimes", DbType.String)
.WithNullableColumn("Language", DbType.String)
.WithNotNullableColumn("Path", DbType.String)
.WithNotNullableColumn("Monitored", DbType.Boolean)
.WithNotNullableColumn("QualityProfileId", DbType.Int16)
.WithNotNullableColumn("SeasonFolder", DbType.Boolean)
.WithNullableColumn("LastInfoSync", DbType.DateTime)
.WithNullableColumn("LastDiskSync", DbType.DateTime);
db.CreateTable("Episodes")
.WithPrimaryKeyColumn("EpisodeId", DbType.Int32).AsIdentity()
.WithNullableColumn("TvDbEpisodeId", DbType.Int32)
.WithNotNullableColumn("SeriesId", DbType.Int32)
.WithNotNullableColumn("SeasonNumber", DbType.Int16)
.WithNotNullableColumn("EpisodeNumber", DbType.Int16)
.WithNotNullableColumn("Title", DbType.String).HavingDefault(String.Empty)
.WithNotNullableColumn("Overview", DbType.String).HavingDefault(String.Empty)
.WithNotNullableColumn("Ignored", DbType.Boolean).HavingDefault(false)
.WithNullableColumn("EpisodeFileId", DbType.Int32)
.WithNullableColumn("AirDate", DbType.DateTime)
.WithNullableColumn("GrabDate", DbType.DateTime);
db.CreateTable("EpisodeFiles")
.WithPrimaryKeyColumn("EpisodeFileId", DbType.Int32).AsIdentity()
.WithNotNullableColumn("SeriesId", DbType.Int32)
.WithNotNullableColumn("Path", DbType.String)
.WithNotNullableColumn("Quality", DbType.Int16)
.WithNotNullableColumn("Proper", DbType.Int16)
.WithNotNullableColumn("Size", DbType.Int64)
.WithNotNullableColumn("DateAdded", DbType.DateTime)
.WithNotNullableColumn("SeasonNumber", DbType.Int16);
db.CreateTable("Config")
.WithNotNullableColumn("Key", DbType.String).Unique()
.WithNotNullableColumn("Value", DbType.String);
}
}
}

View File

@ -5,7 +5,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using Migrator.Framework; using Migrator.Framework;
using MigSharp;
using NLog; using NLog;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Repository.Quality;
@ -19,6 +18,8 @@ namespace NzbDrone.Core.Datastore
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static bool IsMigrated { get; private set; }
public static void Run(string connetionString, bool trace) public static void Run(string connetionString, bool trace)
{ {
Logger.Info("Preparing run database migration"); Logger.Info("Preparing run database migration");
@ -51,20 +52,9 @@ namespace NzbDrone.Core.Datastore
} }
} }
public static void MigrateDatabase(string connectionString)
{
var migrator = new MigSharp.Migrator(connectionString, ProviderNames.SQLite);
migrator.MigrateAll(typeof(MigrationsHelper).Assembly);
}
public static void ForceSubSonicMigration(IRepository repository) public static void ForceSubSonicMigration(IRepository repository)
{ {
repository.Single<Series>(1);
repository.Single<Episode>(1);
repository.Single<EpisodeFile>(1);
repository.Single<QualityProfile>(1); repository.Single<QualityProfile>(1);
repository.Single<History>(1);
repository.Single<IndexerSetting>(1); repository.Single<IndexerSetting>(1);
repository.Single<SceneNameMapping>(1); repository.Single<SceneNameMapping>(1);
} }

View File

@ -130,9 +130,6 @@
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath> <HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="MigSharp">
<HintPath>..\Libraries\MigSharp.dll</HintPath>
</Reference>
<Reference Include="MvcMiniProfiler, Version=2.1.4183.14740, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MvcMiniProfiler, Version=2.1.4183.14740, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MiniProfiler.1.3\lib\MvcMiniProfiler.dll</HintPath> <HintPath>..\packages\MiniProfiler.1.3\lib\MvcMiniProfiler.dll</HintPath>
@ -174,8 +171,7 @@
<Compile Include="Datastore\MigrationLogger.cs" /> <Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" /> <Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" /> <Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\MigrationExport.cs" /> <Compile Include="Datastore\Migrations\Migration.cs" />
<Compile Include="Datastore\Migrations\Legacy\Migration.cs" />
<Compile Include="Datastore\RepositoryProvider.cs" /> <Compile Include="Datastore\RepositoryProvider.cs" />
<Compile Include="Datastore\SqliteProvider.cs" /> <Compile Include="Datastore\SqliteProvider.cs" />
<Compile Include="Helpers\EpisodeRenameHelper.cs" /> <Compile Include="Helpers\EpisodeRenameHelper.cs" />