Replaced MigSharp with MigrationsDotNet
This commit is contained in:
parent
63023d447d
commit
46ec4fa3ba
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -9,11 +9,11 @@ namespace Migrator.Providers
|
|||
/// <summary>
|
||||
/// Defines the implementations specific details for a particular database.
|
||||
/// </summary>
|
||||
public abstract class Dialect
|
||||
public abstract class Dialect
|
||||
{
|
||||
private readonly Dictionary<ColumnProperty, string> propertyMap = new Dictionary<ColumnProperty, string>();
|
||||
private readonly TypeNames typeNames = new TypeNames();
|
||||
|
||||
|
||||
protected Dialect()
|
||||
{
|
||||
RegisterProperty(ColumnProperty.Null, "NULL");
|
||||
|
@ -26,9 +26,9 @@ namespace Migrator.Providers
|
|||
|
||||
public ITransformationProvider NewProviderForDialect(string connectionString)
|
||||
{
|
||||
return (ITransformationProvider) Activator.CreateInstance(TransformationProvider, this, connectionString);
|
||||
return (ITransformationProvider)Activator.CreateInstance(TransformationProvider, this, connectionString);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Subclasses register a typename for the given type code and maximum
|
||||
/// column length. <c>$l</c> in the type name will be replaced by the column
|
||||
|
@ -56,9 +56,9 @@ namespace Migrator.Providers
|
|||
public ColumnPropertiesMapper GetColumnMapper(Column column)
|
||||
{
|
||||
string type = column.Size > 0 ? GetTypeName(column.Type, column.Size) : GetTypeName(column.Type);
|
||||
if (! IdentityNeedsType && column.IsIdentity)
|
||||
if (!IdentityNeedsType && column.IsIdentity)
|
||||
type = String.Empty;
|
||||
|
||||
|
||||
return new ColumnPropertiesMapper(this, type);
|
||||
}
|
||||
|
||||
|
@ -100,15 +100,15 @@ namespace Migrator.Providers
|
|||
public virtual string GetTypeName(DbType type, int length, int precision, int scale)
|
||||
{
|
||||
string resultWithLength = typeNames.Get(type, length, precision, scale);
|
||||
if (resultWithLength != null)
|
||||
if (resultWithLength != null)
|
||||
return resultWithLength;
|
||||
|
||||
return GetTypeName(type);
|
||||
}
|
||||
|
||||
|
||||
public void RegisterProperty(ColumnProperty property, string sql)
|
||||
{
|
||||
if (! propertyMap.ContainsKey(property))
|
||||
if (!propertyMap.ContainsKey(property))
|
||||
{
|
||||
propertyMap.Add(property, sql);
|
||||
}
|
||||
|
@ -128,22 +128,22 @@ namespace Migrator.Providers
|
|||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
|
||||
public virtual bool TableNameNeedsQuote
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
|
||||
public virtual bool ConstraintNameNeedsQuote
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
|
||||
public virtual bool IdentityNeedsType
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
|
||||
public virtual bool NeedsNotNullForIdentity
|
||||
{
|
||||
get { return true; }
|
||||
|
@ -153,28 +153,40 @@ namespace Migrator.Providers
|
|||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
|
||||
public virtual string Quote(string value)
|
||||
{
|
||||
return String.Format(QuoteTemplate, value);
|
||||
}
|
||||
|
||||
|
||||
public virtual string QuoteTemplate
|
||||
{
|
||||
get { return "\"{0}\""; }
|
||||
}
|
||||
|
||||
|
||||
public virtual string Default(object defaultValue)
|
||||
{
|
||||
if (defaultValue is String && defaultValue == String.Empty)
|
||||
{
|
||||
defaultValue = "''";
|
||||
}
|
||||
|
||||
return String.Format("DEFAULT {0}", defaultValue);
|
||||
}
|
||||
|
||||
|
||||
public ColumnPropertiesMapper GetAndMapColumnProperties(Column column)
|
||||
{
|
||||
ColumnPropertiesMapper mapper = GetColumnMapper(column);
|
||||
mapper.MapColumnProperties(column);
|
||||
if (column.DefaultValue != null)
|
||||
{
|
||||
if (column.DefaultValue is String && column.DefaultValue.ToString() == string.Empty)
|
||||
{
|
||||
column.DefaultValue = @"''";
|
||||
}
|
||||
|
||||
mapper.Default = column.DefaultValue;
|
||||
}
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<Item>unsafe</Item>
|
||||
<Item>volatile</Item>
|
||||
</MODIFIERS_ORDER>
|
||||
<WRAP_LIMIT>140</WRAP_LIMIT>
|
||||
</FormatSettings>
|
||||
<UsingsSettings />
|
||||
<Naming2>
|
||||
|
|
|
@ -73,9 +73,7 @@ namespace NzbDrone.Core.Test.Framework
|
|||
}
|
||||
|
||||
var connectionString = Connection.GetConnectionString(fileName);
|
||||
|
||||
MigrationsHelper.MigrateDatabase(connectionString);
|
||||
|
||||
|
||||
var database = Connection.GetPetaPocoDb(connectionString);
|
||||
|
||||
return database;
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
public static IDatabase GetPetaPocoDb(string connectionString)
|
||||
{
|
||||
MigrationsHelper.Run(connectionString, true);
|
||||
|
||||
var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString));
|
||||
|
||||
Database.Mapper = new CustomeMapper();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Migrator.Framework;
|
||||
using MigSharp;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
|
@ -19,6 +18,8 @@ namespace NzbDrone.Core.Datastore
|
|||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static bool IsMigrated { get; private set; }
|
||||
|
||||
public static void Run(string connetionString, bool trace)
|
||||
{
|
||||
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)
|
||||
{
|
||||
repository.Single<Series>(1);
|
||||
repository.Single<Episode>(1);
|
||||
repository.Single<EpisodeFile>(1);
|
||||
repository.Single<QualityProfile>(1);
|
||||
repository.Single<History>(1);
|
||||
repository.Single<IndexerSetting>(1);
|
||||
repository.Single<SceneNameMapping>(1);
|
||||
}
|
||||
|
|
|
@ -130,9 +130,6 @@
|
|||
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
|
||||
</Reference>
|
||||
<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">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MiniProfiler.1.3\lib\MvcMiniProfiler.dll</HintPath>
|
||||
|
@ -174,8 +171,7 @@
|
|||
<Compile Include="Datastore\MigrationLogger.cs" />
|
||||
<Compile Include="Datastore\MigrationsHelper.cs" />
|
||||
<Compile Include="Datastore\CustomeMapper.cs" />
|
||||
<Compile Include="Datastore\Migrations\MigrationExport.cs" />
|
||||
<Compile Include="Datastore\Migrations\Legacy\Migration.cs" />
|
||||
<Compile Include="Datastore\Migrations\Migration.cs" />
|
||||
<Compile Include="Datastore\RepositoryProvider.cs" />
|
||||
<Compile Include="Datastore\SqliteProvider.cs" />
|
||||
<Compile Include="Helpers\EpisodeRenameHelper.cs" />
|
||||
|
|
Loading…
Reference in New Issue