public void AddMigrationError(MigrationVersion version, DocumentMigrationError documentMigrationError) { var d = new Dictionary<string, object> { { "DocumentId", new BsonString(documentMigrationError.DocumentId) }, { "Error", new BsonString(documentMigrationError.Error) } }; GetMigrationsCollection().Update(Query.EQ("_id", new BsonString(version.ToString())), Update.Push("FailedMigrations", new BsonDocument(d))); }
private static void Run() { // create migration table (if it does not exist) _migrationManager.InitMigrationTable(); // retrieve current version MigrationVersion currentVersion = _migrationManager.GetCurrentVersion(); // retrieve sql migration scripts to run MigrationScript[] _artifactScripts = _migrationScriptConverter.GetMigrationScripts(_migrationScriptsFolder, _settings.IncludeSubFolders); if (_artifactScripts == null || !_artifactScripts.Any()) { Exit(_settings.DebugMode, "No sql migration scripts found", _artifactContentFolder); return; } MigrationScript[] scriptsToRun = GetScriptsToRun(_artifactScripts, currentVersion); if (!scriptsToRun.Any()) { Exit(_settings.DebugMode, "Database is up to date, no upgraded required", _artifactContentFolder); return; } // run scripts foreach (MigrationScript script in scriptsToRun) { Console.WriteLine(string.Format("Applying migration {0} version", script.Version.ToString())); _migrationManager.Upgrade(script); Console.WriteLine(string.Format("Migration {0} version done", script.Version.ToString())); Console.WriteLine(); } currentVersion = _migrationManager.GetCurrentVersion(); Exit(_settings.DebugMode, string.Format("Database version = '{0}'", currentVersion.ToString()), _artifactContentFolder); return; }
private void ValidateMigration(MigrationScript migrationScript) { switch (this._migrationStrategy) { case MigrationStrategy.Forward: MigrationVersion currentVersion = this.GetCurrentVersion(); if (currentVersion.Version >= migrationScript.Version.Version) { throw new ApplicationException(string.Format("Attempt to target the database to version {0}; the current version {1} is higher", migrationScript.Version.ToString(), currentVersion.ToString())); } break; case MigrationStrategy.Version: // ignore break; default: throw new ApplicationException(string.Format("Migration strategy not recognized {0}", this._migrationStrategy.ToString())); } }
private static Sql GetInsertStatement(string name, MigrationVersion version) { return(new Sql("INSERT INTO [dbo].[Migration] ([Id], [Name], [Version]) VALUES (@0, @1, @2)", version.ToString(), name, version.ToJsonObject())); }
public virtual void SetMigrationLastId(MigrationVersion version, string id) { GetMigrationsCollection().Update(Query.EQ("_id", new BsonString(version.ToString())), Update.Set("LastCompletedId", id)); }
protected string LoadSqlFile(string fileName) { var fullFilePath = "Migrations.Migration" + MigrationVersion.ToString().PadLeft(3, '0') + "." + fileName; return(DbProvider.LoadSqlFile <IDbProvider>(fullFilePath)); }
public void ToStringWorks() { var mv = new MigrationVersion(new DateTime(2001, 1, 1), "test"); mv.ToString().Should().Be("M20010101000000_test"); }