diff --git a/Libraries/MigSharp.dll b/Libraries/MigSharp.dll deleted file mode 100644 index d0c265902..000000000 Binary files a/Libraries/MigSharp.dll and /dev/null differ diff --git a/Libraries/MigSharp.xml b/Libraries/MigSharp.xml deleted file mode 100644 index 1dc15a3fc..000000000 --- a/Libraries/MigSharp.xml +++ /dev/null @@ -1,1335 +0,0 @@ - - - - MigSharp - - - - - Represents a type that knows how to provide database-specific DDL statements. - - - - - Checks whether a user created table exists on the database. The returned SQL command must yield 0 if the table does not exist. - - The database name. - The table name. - The SQL command to be executed. - - - - Converts an object to its SQL representation for scripting. - - - - - Creates a tables with the specified - - The name of the new table. - The columns of the new table. - Empty if there are no primary key columns. - The SQL commands to be executed. - - - - Drops a table. - - The SQL commands to be executed. - - - - Adds columns to an existing table. - - The SQL commands to be executed. - - - - Renames an existing table. - - The SQL commands to be executed. - - - - Renames a column of an existing table. - - The SQL commands to be executed. - - - - Removes a column from an existing table. - - The SQL commands to be executed. - - - - Changes the data type of a column. - - The SQL commands to be executed. - - - - Adds an index to a table. - - The SQL commands to be executed. - - - - Drops an index from a table. - - The SQL commands to be executed. - - - - Adds a foreign key constraint to a table. - - The SQL commands to be executed. - - - - Drops a foreign key constraint from a table. - - The SQL commands to be executed. - - - - Adds a primary key constraint to a table. - - The SQL commands to be executed. - - - - Renames the primary key. - - The SQL commands to be executed. - - - - Drops a primary key constraint from a table. - - The SQL commands to be executed. - - - - Adds an unique constraint to a table. - - The SQL commands to be executed. - - - - Drops a unique constraint from a table. - - The SQL commands to be executed. - - - - Drops the default value (constraint) from a column. - - The SQL commands to be executed. - - - - Represents the main entry point to perform migrations. - - - - - Initializes a new instance of . - - Connection string to the database to be migrated. - The name of the provider that should be used for this migrator (). - Options. - - - - Initializes a new instance of for a specific module. - - Connection string to the database to be migrated. - The name of the provider that should be used for this migrator (). - The name of the module whose migrations should be executed. - - - - Initializes a new instance of with default options. - - Connection string to the database to be migrated. - The name of the provider that should be used for this migrator (). - - - - Executes all pending migrations found in . - - The assembly to search for migrations. - Optional assemblies that hold additional migrations. - - - - Executes all migrations required to reach . - - - - Optional assemblies that hold additional migrations. - - - - Retrieves all pending migrations. - - The assembly that contains the migrations. - Optional assemblies that hold additional migrations. - - - - Retrieves all required migrations to reach . - - The assembly that contains the migrations. - The timestamp to migrate to. - When the migration path would require downgrading a migration which is not reversible. - Optional assemblies that hold additional migrations. - - - - Checks if any migrations are pending to be performed. - - The assembly that contains the migrations. - Optional assemblies that hold additional migrations. - - - - Injects a custom version mechanism. - - - - - Injects a custom bootstrapping mechanism. - - - - - Represents a database. - - - - - Creates a new table on the database. - - The name of the new table. - Optionally, the name of the primary key constraint. - - - - Executes a custom query. - - Custom SQL which must be understood by all providers that should be supported by this migration. - - - - Executes a custom action against the . Use this method if you need to directly access the - underlying or . - - - - - Gets the context of the migration. - - - - - Gets existing tables. - - - - - Contains the extension methods for the interface. - - - - - Creates a new table on the database with a default primary key constraint name. - - - - - Represents the context of a migration. - - - - - Gets the metadata describing the underlying provider. - - - - - Represents an index. - - - - - Drops the index. - - - - - Represents an index which is about to be added to a table. - - - - - Adds the index on the provided column. - - - - - Represents a primary key constraint which is about to be added to a table. - - - - - Adds the index on the provided column. - - - - - Represents a batch of s. - - - - - Performs the migrations contained in this batch. - - - - - Raised before each migration that will be executed. - - - - - Raised after each migration that has been executed. - - - - - Gets the number of migrations in this batch. - - - - - Gets a list of s that were used to create new objects (excluding primary key columns). - - - - - Gets a list of s that were used to create primary key columns. - - - - - Gets a list of names of any created objects. - - - - - Gets a list of method names that were used for the migration. - - - - - Represents a collection of existing indexes of a table. - - - - - Gets an index by name. - - - - - Represents an unique constraint. - - - - - Drops the unique constraint. - - - - - Represents a foreign key constraint. - - - - - Drops the foreign key constraint. - - - - - Executes the migration step and updates the versioning information in one transaction. - - Might be null in the case of a bootstrap step. - - - - Executes the migration step and updates the versioning information in one transaction. - - - - - Represents a pair of column names which is used as an element of a foreign key relationship. - - - - - Gets the name of the referencing column. - - - - - Gets the name of the referenced column. - - - - - Represents the version of a database containing all information about past migrations. - - - - - Verifies if a specific migration was executed. - - It might seems odd that this method does not receive a connection. However, the idea is that the object implementing - this interface initializes itself once upon construction and the answers the calls to this method from a cache. - Thus, it would not need to do any round-trip to the database which is important as this method is called for each migration. - - - - - - Updates the versioning to include or exclude the migration depending on the provided . - - Post-condition: if was , must return true. - Otherwise was and must return false. - - - The metadata of the migration to be included in the versioning table. - An open connection to the database containing the versioning table. - The associated transaction. - The direction of the migration. - Used to execute s. - - - - Represents a created table. - - - - - Represents a created table. - - - - - Adds a non-nullable column which is part of the primary key constraint to the table being created. - - - - - Adds a non-nullable column to the table being created. - - - - - Adds a nullable column to the table being created. - - - - - Gets the name of the table. - - - - - Represents a unique constraint which is about to be added to a table. - - - - - Adds the unique constraint on the provided column. - - - - - Declares the support of a specific data type. - - - - - Initializes a new instance. - - - - - Gets the supported data type. - - - - - Gets or sets the maximum length for character data types or the maximum total number of decimal digits for numeric data types. - - - - - Gets or sets the maximum number of decimal digits that can be stored to the right of the decimal point. Scale is a value from 0 through . - - - - - Indicates if the data type can be used in primary key columns. By default, this is false. - - - - - Gets or sets a warning message if there are any restrictions when using this . - The warning message is logged when executing a migration containing this data type. - - - - - Indicates if the data type can be scripted. - - - - - Represents an added column on an existing table. - - - - - Represents a table that was created before. - - - - - Adds a not-nullable column. - - - - - Adds a nullable column. - - - - - Gets the name of the table. - - - - - Specifies the size and the scale of the data type of the column. - - The length for character data types or the maximum total number of decimal digits for numeric data types. - The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through . - - - - Adds a default value to the column. - - - - - Adds a default value to the column. - - - - - Adds a default value to the column which is dropped after adding the column to the table. - Use this method to fill a non-nullable column with default values. - - - - - Adds a default value to the column which is dropped after adding the column to the table. - Use this method to fill a non-nullable column with default values. - - - - - Contains the extensions methods for the interface. - - - - - Specifies the size of the data type of the column. - - - The length for character data types or the maximum total number of decimal digits for numeric data types. - - - - Sets the default of the column to be the current system time of the database server. - - - - - Reperesents metadata about an . - - - - - Gets the unique name of this provider. - - - - - Gets the invariant name of the provider needed for . - - - - - Gets an indication if the underlying provider supports transactions. - - - - - Gets an expression that specifies how s are addressed in command texts. The literal 'p' is replaced by the parameter name. - - - - - Gets the maximum length of object names within the database. 0 meaning that there is non restriction which is the default. - - - - - Represents a column on a newly created table. - - - - - Specifies the size and the scale of the data type of the column. - - The length for character data types or the maximum total number of decimal digits for numeric data types. - The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through . - - - - Puts the column under an unique constraint. - - Optionally, specify the name of the unique constraint. If null or empty, a default constraint name will be generated. - - - - Makes the column auto-increment. - - - - - Adds a default value to the column. - - - - - Adds a default value to the column. - - - - - Gets the column name. - - - - - This exception is thrown when a requested downgrade path contains an irreversible migration. - - - - - Contains the names of the supported providers. - - - - - Represents the run-time context of a migration. - - - - - Gets the connection which is used to perform the migration. - - - - - Gets the transaction which is used to perform the migration. - - - - - Gets the that should be used to execute database modifying commands. - This ensures that they are logged and scripted consistently. - - - - - Lists special default values for columns. - - - - - Represents the current date time of the database server. - - - - - Represents a collection of providers that should be supported for all migrations. Validation of migrations is performed - against providers contained within this list. - - - - - Initializes a new instance used for unit testing. - - - - - Initializes a new instance which is ready-to-use with the default providers. - - - - - Adds a provider. - - - - - Removes a provider. - - - - - Removes all ODBC providers. - - - - - Sets the collection to a list of providers. - - - - - Resets the collection to support all providers that are delivered with Mig#. - - - - - Gets the names of the providers. - - - - - Represents a collection of existing unique constraints of a table. - - - - - Gets an unique constraint by name. - - - - - Use this attribute to mark classes as migrations. - - - - - The maximum string length for a module name. - - - - - Initializes a new instance of the attribute. - - - - - Gets the name of the module to which this migration belongs to (see also ). - - - - - Gets the tag associated with this migration. - - - - - Represents a migration that can also be downgraded. - - - - - The interface that needs to be implemented in order to define a migration. - Additionally, the must be applied - to a class implementing this interface in order to be recognized as a migration. - - - - - Applies the required changes to the provided for this migration. - - - - - Undoes all changes from the method. - - - - - Represents a foreign key constraint which is about to be added to a table. - - - - - Specifies the columns on which the foreign key is defined. - - - This method is not called 'On', as 'On' is a reserved language keyword (see FxCop rule "Identifiers should not match keywords"). - - - - - Contains information about used data types, longest name, etc. for a specific migration. - - - - - Gets the full type name of the migration for this report. - - - - - Gets the error message for the migration if there was an . - - - - - Gets a list of s that were used to create new objects (including primary key columns). - - - - - Gets a list of s that were used to create primary key columns. - - - - - Gets the longest name of any created objects. - - - - - Gets a list of used provider method names. - - - - - Marks the class as an provider implementing . - - - - - Initializes a new instance. - - - - - Gets the unique name of this provider. - - - - - Gets the invariant name of the provider needed for . - - - - - Gets or sets an indication if the underlying provider supports transactions. True by default. - - - - - Gets an expression that specifies how s are addressed in command texts. The literal 'p' is replaced by the parameter name. - The default is '@p'. - - - - - Gets or sets the maximum length of object names within the database. 0 meaning that there is non restriction which is the default. - - - - - Represents a collection of existing foreign key constraints of a table. - - - - - Gets an foreign key constraint by name. - - - - - Represents an existing column whose data type is being altered. - - - - - Specifies the size and the scale of the new data type of the column. - - The length for character data types or the maximum total number of decimal digits for numeric data types. - The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through . - - - - Adds a default value to the column. - - - - - Adds a default value to the column. - - - - - Contains the extensions methods for the interface. - - - - - Specifies the size of the new data type of the column. - - - The length for character data types or the maximum total number of decimal digits for numeric data types. - - - - Sets the default of the column to be the current system time of the database server. - - - - - MigSharp provider for Microsoft SQL Compact Edition 4.0. - - - - - Represents a collection of existing tables. - - - - - Gets a table by its name. - - - - - Represents a collection of existing columns. - - - - - Gets a column by its name. - - - - - Represents an existing column. - - - - - Renames the column. - - - - - Removes the column from its table. - - - - - Alters the column to be a nullable column. - - A new or the old data type of the column. - - - - Alters the column to be a nullable column. - - A new or the old data type of the column. - - - - Gets the name of the column. - - - - - Gets the name of the table of the column. - - - - - Contains the extensions methods for the interface. - - - - - Specifies the size of the data type of the column. - - - The length for character data types or the maximum total number of decimal digits for numeric data types. - - - - Puts the column under an unique constraint with a default constraint name. - - - - - Sets the default of the column to be the current system time of the database server. - - - - - Visits all commands executed against a and translates them into SQL - using a specific . - - - - - Translates the recorded commands on the to SQL commands. - - - - - Represents a SQL data type. - - - - - Initializes a new instance of . - - - - - Used in validation messages and for debugging. - - - - - Gets the length for character data types or the maximum total number of decimal digits for numeric data types. - - - - - Gets the maximum number of decimal digits that can be stored to the right of the decimal point. Scale is a value from 0 through . - - - - - Use this class to configure the behaviour of the . - - - - - Initializes an instance of default options. - - - - - Initializes options that select migrations for specific module only. - - The name of the selected module. Only migrations for this module will be executed. - - - - Suppresses validation warnings for the provider called and the data type under the . - - - - - Outputs the SQL used for the migrations to external files without affecting the database. - - - - - Outputs the SQL used for the migrations to external files without affecting the database. - - - - - Outputs the SQL used for the migrations to external files while migrating the database. - - - - - Outputs the SQL used for the migrations to external files while migrating the database. - - - - - Sets the level of general information being traced. - - - - - Sets the level of SQL information being traced. - - - - - Sets the level of performance information being traced. - - - - - Gets or sets the table name of the versioning table. - - - - - Gets the providers that should be supported for all migrations. Compatibility validation of migrations is performed - against the providers in this collection. - - - - - Gets or sets a function that selects the module based on its name. Only migrations for this module will be executed. - - - - - Expresses under which circumstances a warning should be expressed for a given and its OfSize parameters. - - - - - Suppresses all warnings for the specified . Use diligently. - - - - - Suppresses warnings for the specified when it is used without a specified size. - - - - - Suppresses warnings for the specified when it is used with a specified size. - - - - - Suppresses warnings for the specified when it is used with a specified size and a specified scale. - - - - - Validates s against the list of supported providers. - - - - - Represents a table that was created before. - - - - - Gets the primary key constraint of the table. - - Optionally, the name of the primary key constraint. If null or empty, the default name will be used. - - - - Renames the table. - - - - - Drops the table. - - - - - Adds a primary key constraint to the table. - - Optionally, the primary key constraint name. If null or empty, a default name will be generated. - - - - Adds an index to the table. - - Optionally, the index name. If null or empty, a default name will be generated. - - - - Adds a foreign key constraint to another table. - - The name of the referenced table. - Optionally, the name of the foreign key constraint. If null or empty, a default name will be generated. - - - - Adds an unique constraint to the table. - - Optionally, the name of the unique constraint. If null or empty, a default name will be generated. - - - - Gets the columns of the table. - - - - - Gets the unique constraints of the table. - - - - - Gets the unique constraints of the table. - - - - - Gets the foreign key constraints of the table. - - - - - Represents a primary key constraint. - - - - - Drops the primary key constraint. - - - - - Renames the primary key constraint and all associated resources (e.g. Oracle maintains an index along with the primary key which is renamed, too). - - - - - - Returns the longer string. - - - - - Returns the longest string. - - - - - Creates a name with the following structure: '_[0]_[1]_..._'. - The contained names are shortened such that the complete generated name fits characters. - - The table name. - The postfix to be appended to the name. The postfix will *not* be shortened in any way. - The maximum length of the generated name. - Additional names that should be included in the result which follow the table name. - - - - Event arguments for migration events. - - - - - Initializes a new instance. - - - - - Gets the associated metadata. - - - - - Gets the direction of the migration step. - - - - - Implements a custom bootstrapping logic which is executed if the versioning table of MigSharp doe not exists yet. - - - - - Triggers whatever actions are needed to prepare the custom bootstrapping. This method is called exactly once, - before is called any times. - - The connection used to update the versioning table. - The transaction used to update the versioning table. - - - - Returns true if the migration should be assumed as already executed when bootstrapping the versioning. - - - - - Triggers whatever actions are needed to finish the custom bootstrapping. This method is called exactly once, - after is called any times. - - The connection used to update the versioning table. - The transaction used to update the versioning table. - - - - Contains extension methods for the interface. - - - - - Gets the primary key constraint of the table with the default name. - - - - - Adds a primary key constraint to the table with the default name. - - - - - Adds an index to the table. - - - - - Adds a foreign key constraint to another table with the default name. - - - The name of the referenced table. - - - - Adds an unique constraint to the table with the default name. - - - - - Gets an unique constraint by the name of its first column. - - - - - Gets an foreign key constraint by the name of its referenced table. - - - - - Implements without creating a versioning table until it is really needed. - - - - diff --git a/Migrator.net/Migrator.Providers/Dialect.cs b/Migrator.net/Migrator.Providers/Dialect.cs index 11df04dde..6c1a2fabf 100644 --- a/Migrator.net/Migrator.Providers/Dialect.cs +++ b/Migrator.net/Migrator.Providers/Dialect.cs @@ -9,11 +9,11 @@ namespace Migrator.Providers /// /// Defines the implementations specific details for a particular database. /// - public abstract class Dialect + public abstract class Dialect { private readonly Dictionary propertyMap = new Dictionary(); private readonly TypeNames typeNames = new TypeNames(); - + protected Dialect() { RegisterProperty(ColumnProperty.Null, "NULL"); @@ -26,9 +26,9 @@ protected Dialect() public ITransformationProvider NewProviderForDialect(string connectionString) { - return (ITransformationProvider) Activator.CreateInstance(TransformationProvider, this, connectionString); + return (ITransformationProvider)Activator.CreateInstance(TransformationProvider, this, connectionString); } - + /// /// Subclasses register a typename for the given type code and maximum /// column length. $l in the type name will be replaced by the column @@ -56,9 +56,9 @@ protected void RegisterColumnType(DbType code, string name) 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 @@ public virtual string GetTypeName(DbType type, int length) 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 @@ public virtual bool ColumnNameNeedsQuote { 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 @@ public virtual bool SupportsIndex { 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; } } diff --git a/NzbDrone.5.1.ReSharper b/NzbDrone.5.1.ReSharper index 6b649dee3..a23a81a3a 100644 --- a/NzbDrone.5.1.ReSharper +++ b/NzbDrone.5.1.ReSharper @@ -21,6 +21,7 @@ unsafe volatile + 140 diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index 85c4cb554..b0585ea21 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -73,9 +73,7 @@ public static IDatabase GetEmptyDatabase(bool enableLogging = false, string file } var connectionString = Connection.GetConnectionString(fileName); - - MigrationsHelper.MigrateDatabase(connectionString); - + var database = Connection.GetPetaPocoDb(connectionString); return database; diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index 1c45779db..e6ecd8a1c 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -59,6 +59,8 @@ public static IRepository CreateSimpleRepository(string connectionString) public static IDatabase GetPetaPocoDb(string connectionString) { + MigrationsHelper.Run(connectionString, true); + var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString)); Database.Mapper = new CustomeMapper(); diff --git a/NzbDrone.Core/Datastore/Migrations/Legacy/Migration.cs b/NzbDrone.Core/Datastore/Migrations/Legacy/Migration.cs deleted file mode 100644 index 2d5f74f2c..000000000 --- a/NzbDrone.Core/Datastore/Migrations/Legacy/Migration.cs +++ /dev/null @@ -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(); - } - } -} diff --git a/NzbDrone.Core/Datastore/Migrations/Migration.cs b/NzbDrone.Core/Datastore/Migrations/Migration.cs new file mode 100644 index 000000000..b26e4cd12 --- /dev/null +++ b/NzbDrone.Core/Datastore/Migrations/Migration.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs b/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs deleted file mode 100644 index d7714ab1a..000000000 --- a/NzbDrone.Core/Datastore/Migrations/MigrationExport.cs +++ /dev/null @@ -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); - } - } -} diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs index 192c1cd23..fb610e587 100644 --- a/NzbDrone.Core/Datastore/MigrationsHelper.cs +++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs @@ -5,7 +5,6 @@ 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 @@ public class MigrationsHelper { 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 @@ public static void Run(string connetionString, bool trace) } } - - 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(1); - repository.Single(1); - repository.Single(1); repository.Single(1); - repository.Single(1); repository.Single(1); repository.Single(1); } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index a4df3b791..b3208e305 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -130,9 +130,6 @@ ..\Libraries\Exceptioneer.WindowsFormsClient.dll - - ..\Libraries\MigSharp.dll - False ..\packages\MiniProfiler.1.3\lib\MvcMiniProfiler.dll @@ -174,8 +171,7 @@ - - +