From a0560da33db813569c2bca5c673609a49f5d3f43 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 31 Mar 2013 16:04:21 -0700 Subject: [PATCH] simplified migrations. --- .../Migration/Framework/MigrationExtension.cs | 14 + .../Datastore/Migration/Migration20130324.cs | 254 ++++++++---------- NzbDrone.Core/NzbDrone.Core.csproj | 1 + 3 files changed, 132 insertions(+), 137 deletions(-) create mode 100644 NzbDrone.Core/Datastore/Migration/Framework/MigrationExtension.cs diff --git a/NzbDrone.Core/Datastore/Migration/Framework/MigrationExtension.cs b/NzbDrone.Core/Datastore/Migration/Framework/MigrationExtension.cs new file mode 100644 index 000000000..565630165 --- /dev/null +++ b/NzbDrone.Core/Datastore/Migration/Framework/MigrationExtension.cs @@ -0,0 +1,14 @@ +using FluentMigrator.Builders.Create; +using FluentMigrator.Builders.Create.Table; + +namespace NzbDrone.Core.Datastore.Migration.Framework +{ + public static class MigrationExtension + { + public static ICreateTableColumnOptionOrWithColumnSyntax TableForModel(this ICreateExpressionRoot expressionRoot, string name) + { + return expressionRoot.Table(name).WithColumn("Id").AsInt32().PrimaryKey().Identity(); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs index 879857db2..0be6fcbf9 100644 --- a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs +++ b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs @@ -9,157 +9,137 @@ namespace NzbDrone.Core.Datastore.Migration { protected override void MainDbUpgrade() { - Create.Table("Config") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Key").AsString().PrimaryKey() - .WithColumn("Value").AsString().NotNullable(); - - Create.Table("EpisodeFiles") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("SeriesId").AsInt32().NotNullable() - .WithColumn("Path").AsString().NotNullable() - .WithColumn("Quality").AsInt32().NotNullable() - .WithColumn("Proper").AsBoolean().NotNullable() - .WithColumn("Size").AsInt64().NotNullable() - .WithColumn("DateAdded").AsDateTime().NotNullable() - .WithColumn("SeasonNumber").AsInt32().NotNullable() + Create.TableForModel("Config") + .WithColumn("Key").AsString().Unique() + .WithColumn("Value").AsString(); + + Create.TableForModel("RootFolders") + .WithColumn("Path").AsString().Unique(); + + Create.TableForModel("Series") + .WithColumn("TvdbId").AsInt32().Unique() + .WithColumn("TvRageId").AsInt32().Unique() + .WithColumn("ImdbId").AsString().Unique() + .WithColumn("Title").AsString() + .WithColumn("TitleSlug").AsString().Unique() + .WithColumn("CleanTitle").AsString() + .WithColumn("Status").AsInt32() + .WithColumn("Overview").AsString().Nullable() + .WithColumn("AirTime").AsString().Nullable() + .WithColumn("Images").AsString() + .WithColumn("Path").AsString().Unique() + .WithColumn("Monitored").AsBoolean() + .WithColumn("QualityProfileId").AsInt32() + .WithColumn("SeasonFolder").AsBoolean() + .WithColumn("LastInfoSync").AsDateTime().Nullable() + .WithColumn("LastDiskSync").AsDateTime().Nullable() + .WithColumn("Runtime").AsInt32() + .WithColumn("SeriesType").AsInt32() + .WithColumn("BacklogSetting").AsInt32() + .WithColumn("Network").AsString().Nullable() + .WithColumn("CustomStartDate").AsDateTime().Nullable() + .WithColumn("UseSceneNumbering").AsBoolean() + .WithColumn("UtcOffSet").AsInt32() + .WithColumn("FirstAired").AsDateTime().Nullable() + .WithColumn("NextAiring").AsDateTime().Nullable(); + + Create.TableForModel("Seasons") + .WithColumn("SeriesId").AsInt32() + .WithColumn("SeasonNumber").AsInt32() + .WithColumn("Ignored").AsBoolean(); + + Create.TableForModel("Episodes") + .WithColumn("TvDbEpisodeId").AsInt32().Unique() + .WithColumn("SeriesId").AsInt32() + .WithColumn("SeasonNumber").AsInt32() + .WithColumn("EpisodeNumber").AsInt32() + .WithColumn("Title").AsString().Nullable() + .WithColumn("Overview").AsString().Nullable() + .WithColumn("Ignored").AsBoolean().Nullable() + .WithColumn("EpisodeFileId").AsInt32().Nullable() + .WithColumn("AirDate").AsDateTime().Nullable() + .WithColumn("GrabDate").AsDateTime().Nullable() + .WithColumn("PostDownloadStatus").AsInt32().Nullable() + .WithColumn("AbsoluteEpisodeNumber").AsInt32().Nullable() + .WithColumn("SceneAbsoluteEpisodeNumber").AsInt32().Nullable() + .WithColumn("SceneSeasonNumber").AsInt32().Nullable() + .WithColumn("SceneEpisodeNumber").AsInt32().Nullable(); + + Create.TableForModel("EpisodeFiles") + .WithColumn("SeriesId").AsInt32() + .WithColumn("Path").AsString().Unique() + .WithColumn("Quality").AsInt32() + .WithColumn("Proper").AsBoolean() + .WithColumn("Size").AsInt64() + .WithColumn("DateAdded").AsDateTime() + .WithColumn("SeasonNumber").AsInt32() .WithColumn("SceneName").AsString().Nullable() .WithColumn("ReleaseGroup").AsString().Nullable(); - Create.Table("Episodes") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("TvDbEpisodeId").AsInt32().Nullable() - .WithColumn("SeriesId").AsInt32().NotNullable() - .WithColumn("SeasonNumber").AsInt32().NotNullable() - .WithColumn("EpisodeNumber").AsInt32().NotNullable() - .WithColumn("Title").AsString().Nullable() - .WithColumn("Overview").AsString().Nullable() - .WithColumn("Ignored").AsBoolean().Nullable() - .WithColumn("EpisodeFileId").AsInt32().Nullable() - .WithColumn("AirDate").AsDateTime().Nullable() - .WithColumn("GrabDate").AsDateTime().Nullable() - .WithColumn("PostDownloadStatus").AsInt32().Nullable() - .WithColumn("AbsoluteEpisodeNumber").AsInt32().Nullable() - .WithColumn("SceneAbsoluteEpisodeNumber").AsInt32().Nullable() - .WithColumn("SceneSeasonNumber").AsInt32().Nullable() - .WithColumn("SceneEpisodeNumber").AsInt32().Nullable(); - - Create.Table("ExternalNotificationDefinitions") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Enable").AsBoolean().NotNullable() - .WithColumn("Type").AsString().NotNullable() - .WithColumn("Name").AsString().NotNullable(); - - Create.Table("History") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("EpisodeId").AsInt32().NotNullable() - .WithColumn("SeriesId").AsInt32().NotNullable() - .WithColumn("NzbTitle").AsString().NotNullable() - .WithColumn("Date").AsDateTime().NotNullable() - .WithColumn("Quality").AsString().NotNullable() - .WithColumn("Indexer").AsString().NotNullable() + Create.TableForModel("History") + .WithColumn("EpisodeId").AsInt32() + .WithColumn("SeriesId").AsInt32() + .WithColumn("NzbTitle").AsString() + .WithColumn("Date").AsDateTime() + .WithColumn("Quality").AsString() + .WithColumn("Indexer").AsString() .WithColumn("NzbInfoUrl").AsString().Nullable() .WithColumn("ReleaseGroup").AsString().Nullable(); - Create.Table("IndexerDefinitions") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Enable").AsBoolean().NotNullable() - .WithColumn("Type").AsString().NotNullable() - .WithColumn("Name").AsString().NotNullable(); - - Create.Table("JobDefinitions") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Enable").AsBoolean().NotNullable() - .WithColumn("Type").AsString().NotNullable() - .WithColumn("Name").AsString().NotNullable() - .WithColumn("Interval").AsInt32().NotNullable() - .WithColumn("LastExecution").AsDateTime().NotNullable() - .WithColumn("Success").AsBoolean().NotNullable(); - - Create.Table("NewznabDefinitions") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Enable").AsBoolean().NotNullable() - .WithColumn("Name").AsString().NotNullable() - .WithColumn("Url").AsString().NotNullable() + Create.TableForModel("ExternalNotificationDefinitions") + .WithColumn("Enable").AsBoolean() + .WithColumn("Type").AsString().Unique() + .WithColumn("Name").AsString().Unique(); + + Create.TableForModel("JobDefinitions") + .WithColumn("Enable").AsBoolean() + .WithColumn("Type").AsString().Unique() + .WithColumn("Name").AsString().Unique() + .WithColumn("Interval").AsInt32() + .WithColumn("LastExecution").AsDateTime() + .WithColumn("Success").AsBoolean(); + + Create.TableForModel("IndexerDefinitions") + .WithColumn("Enable").AsBoolean() + .WithColumn("Type").AsString().Unique() + .WithColumn("Name").AsString().Unique(); + + Create.TableForModel("NewznabDefinitions") + .WithColumn("Enable").AsBoolean() + .WithColumn("Name").AsString().Unique() + .WithColumn("Url").AsString() .WithColumn("ApiKey").AsString().Nullable() - .WithColumn("BuiltIn").AsBoolean().NotNullable(); - - Create.Table("QualityProfiles") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Name").AsString().NotNullable() - .WithColumn("Cutoff").AsInt32().NotNullable() - .WithColumn("Allowed").AsString().NotNullable(); - - Create.Table("QualitySizes") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("QualityId").AsInt32().NotNullable().Unique() - .WithColumn("Name").AsString().NotNullable() - .WithColumn("MinSize").AsInt32().NotNullable() - .WithColumn("MaxSize").AsInt32().NotNullable(); - - Create.Table("RootFolders") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Path").AsString().NotNullable(); - - Create.Table("SceneMappings") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("CleanTitle").AsString().NotNullable() - .WithColumn("SceneName").AsString().NotNullable() - .WithColumn("TvdbId").AsInt32().NotNullable() - .WithColumn("SeasonNumber").AsInt32().NotNullable(); - - Create.Table("Seasons") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("SeriesId").AsInt32().NotNullable() - .WithColumn("SeasonNumber").AsInt32().NotNullable() - .WithColumn("Ignored").AsBoolean().NotNullable(); - - Create.Table("Series") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("TvdbId").AsInt32().NotNullable() - .WithColumn("Title").AsString().NotNullable() - .WithColumn("TitleSlug").AsString().NotNullable() - .WithColumn("CleanTitle").AsString().NotNullable() - .WithColumn("Status").AsInt32().NotNullable() - .WithColumn("Overview").AsString().Nullable() - .WithColumn("AirTime").AsString().Nullable() - .WithColumn("Images").AsString() - .WithColumn("Path").AsString().NotNullable() - .WithColumn("Monitored").AsBoolean().NotNullable() - .WithColumn("QualityProfileId").AsString().NotNullable() - .WithColumn("SeasonFolder").AsBoolean().NotNullable() - .WithColumn("LastInfoSync").AsDateTime().Nullable() - .WithColumn("LastDiskSync").AsDateTime().Nullable() - .WithColumn("Runtime").AsInt32().NotNullable() - .WithColumn("SeriesType").AsInt32().NotNullable() - .WithColumn("BacklogSetting").AsInt32().NotNullable() - .WithColumn("Network").AsString().Nullable() - .WithColumn("CustomStartDate").AsDateTime().Nullable() - .WithColumn("UseSceneNumbering").AsBoolean().NotNullable() - .WithColumn("TvRageId").AsInt32().Nullable() - .WithColumn("TvRageTitle").AsString().Nullable() - .WithColumn("UtcOffSet").AsInt32().NotNullable() - .WithColumn("FirstAired").AsDateTime().Nullable() - .WithColumn("NextAiring").AsDateTime().Nullable(); - - Create.Table("MediaCovers") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("SeriesId").AsInt32().NotNullable() - .WithColumn("Url").AsString().NotNullable() - .WithColumn("CoverType").AsInt32().NotNullable(); + .WithColumn("BuiltIn").AsBoolean(); + + Create.TableForModel("QualityProfiles") + .WithColumn("Name").AsString().Unique() + .WithColumn("Cutoff").AsInt32() + .WithColumn("Allowed").AsString(); + + Create.TableForModel("QualitySizes") + .WithColumn("QualityId").AsInt32().Unique() + .WithColumn("Name").AsString().Unique() + .WithColumn("MinSize").AsInt32() + .WithColumn("MaxSize").AsInt32(); + + Create.TableForModel("SceneMappings") + .WithColumn("CleanTitle").AsString() + .WithColumn("SceneName").AsString() + .WithColumn("TvdbId").AsInt32() + .WithColumn("SeasonNumber").AsInt32(); + } protected override void LogDbUpgrade() { - Create.Table("Logs") - .WithColumn("Id").AsInt32().PrimaryKey().Identity() - .WithColumn("Message").AsString().NotNullable() - .WithColumn("Time").AsDateTime().NotNullable() - .WithColumn("Logger").AsString().NotNullable() + Create.TableForModel("Logs") + .WithColumn("Message").AsString() + .WithColumn("Time").AsDateTime() + .WithColumn("Logger").AsString() .WithColumn("Method").AsString().Nullable() .WithColumn("Exception").AsString().Nullable() .WithColumn("ExceptionType").AsString().Nullable() - .WithColumn("Level").AsString().NotNullable(); + .WithColumn("Level").AsString(); } } } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 80984c8ec..162736cb7 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -200,6 +200,7 @@ +