示例#1
0
        public void RunningSameMigrationTwiceDoesNotFail()
        {
            var database = MongoTest.GetCleanTestDatabase();
            var migrator = new Migrator(database, new[] { new InsertSingleDocument() }, DefaultOptions);

            migrator.Execute();

            migrator.Execute();

            var docs = database.GetCollection <BsonDocument>("docs").Find(d => true).ToList();

            Assert.That(docs.Count, Is.EqualTo(1), "Expected a single document to have been inserted");
            Assert.That(docs.First()["what"].AsString, Is.EqualTo("text"));
        }
示例#2
0
        public static bool Migrate(ISessionCreator factory)
        {
            string[] files =
            {
                Path.Combine(GlobalPaths.UserdataFolder, GlobalPaths.USERDATA_FILE),
                Path.Combine(GlobalPaths.UserdataFolder, "userdata-hc.db")
            };

            foreach (var dbfile in files)
            {
                if (!File.Exists(dbfile))
                {
                    logger.Info("Migration requested but already performed. Halted.");
                    return(true);
                }

                if (!Migrator <PlayerItem> .Execute(factory, CreateLegacySessionFactory(dbfile), dbfile.Contains("-hc")))
                {
                    logger.Warn("Failed to items");
                    return(false);
                }
                else
                {
                    // Rename it, so its not migrated again.
                    if (File.Exists(string.Format("{0}.legacy", dbfile)))
                    {
                        File.Delete(string.Format("{0}.legacy", dbfile));
                    }
                    File.Move(dbfile, string.Format("{0}.legacy", dbfile));
                    logger.Info("Migration successful, old database renamed to .legacy");
                }
            }

            return(true);
        }
示例#3
0
 private void RunMigrations()
 {
     _logger.LogInformation("Running migrations...");
     Migrator.Execute(_dbOptions.Provider, _dbOptions.ConnectionString);
     _logger.LogInformation("Migrations updated");
     _executedMigrations = true;
 }