Ejemplo n.º 1
0
        public bool Validate(IDataConnector genericData)
        {
            if (genericData.GetUniverseVersion (MigrationName) != Version)
                return false;

            return DoValidate(genericData);
        }
Ejemplo n.º 2
0
        public void MigrationTestsTests()
        {
            //IMPORTANT NOTIFICATION
            //Till I figure out a way, please delete the .db file or drop tables clean before running this

            //Switch the comments to test one technology or another
            var technology = DataManagerTechnology.SQLite;
            //var technology = DataManagerTechnology.MySql;

            var    mysqlconnectionstring  = "Data Source=localhost;Database=Universetest;User ID=Universetest;Password=test;";
            var    sqliteconnectionstring = string.Format("URI=file:{0},version=3", dbFileName);
            string connectionString       = (technology == DataManagerTechnology.SQLite)?sqliteconnectionstring:mysqlconnectionstring;

            CreateEmptyDatabase();
            DataSessionProvider sessionProvider = new DataSessionProvider(technology, connectionString);
            IDataConnector      genericData     = ((technology == DataManagerTechnology.SQLite)? (IDataConnector) new SQLiteLoader():new MySQLDataLoader());

            genericData.ConnectToDatabase(connectionString);

            var migrators     = new List <Migrator>();
            var testMigrator0 = new TestMigrator();

            migrators.Add(testMigrator0);

            var migrationManager = new MigrationManager(sessionProvider, genericData, migrators);

            Assert.AreEqual(testMigrator0.Version, migrationManager.LatestVersion, "Latest version is correct");
            Assert.IsNull(migrationManager.GetDescriptionOfCurrentOperation(), "Description should be null before deciding what to do.");
            migrationManager.DetermineOperation();
            var operationDescription = migrationManager.GetDescriptionOfCurrentOperation();

            Assert.AreEqual(MigrationOperationTypes.CreateDefaultAndUpgradeToTarget, operationDescription.OperationType, "Operation type is correct.");
            Assert.AreEqual(testMigrator0.Version, operationDescription.CurrentVersion, "Current version is correct");
            //There will be no migration because there is only one migrator which will provide the default
            Assert.IsNull(operationDescription.StartVersion, "Start migration version is correct");
            Assert.IsNull(operationDescription.EndVersion, "End migration version is correct");
            try
            {
                migrationManager.ExecuteOperation();
                Assert.AreEqual(testMigrator0.Version, genericData.GetUniverseVersion(), "Version of settings is updated");
            }
            catch (MigrationOperationException)
            {
                Assert.Fail("Something failed during execution we weren't expecting.");
            }
            bool valid = migrationManager.ValidateVersion(migrationManager.LatestVersion);

            Assert.AreEqual(true, valid, "Database is a valid version");

            migrationManager.DetermineOperation();
            var operationDescription2 = migrationManager.GetDescriptionOfCurrentOperation();

            Assert.AreEqual(MigrationOperationTypes.DoNothing, operationDescription2.OperationType, "Operation type is correct.");
            Assert.AreEqual(testMigrator0.Version, operationDescription2.CurrentVersion, "Current version is correct");
            Assert.IsNull(operationDescription2.StartVersion, "Start migration version is correct");
            Assert.IsNull(operationDescription2.EndVersion, "End migration version is correct");
            migrationManager.ExecuteOperation();

            genericData.CloseDatabase();
        }
Ejemplo n.º 3
0
 public bool Validate(IDataConnector genericData)
 {
     if (genericData.GetUniverseVersion(MigrationName) != Version)
     {
         return(false);
     }
     return(DoValidate(genericData));
 }
        public void DetermineOperation()
        {
            if (migratorName == "")
            {
                return;
            }
            executed = false;
            Version currentVersion = genericData.GetUniverseVersion(migratorName);

            //if there is no Universe version, this is likely an entirely new installation
            if (currentVersion == null)
            {
                MainConsole.Instance.InfoFormat("[Migrator]: Clean installation for {0} found", migratorName);
                Migrator defaultMigrator = GetHighestVersionMigratorThatCanProvideDefaultSetup();
                currentVersion = defaultMigrator.Version;
                Migrator startMigrator  = GetMigratorAfterVersion(defaultMigrator.Version);
                var      latestMigrator = GetLatestVersionMigrator();
                Migrator targetMigrator = defaultMigrator == latestMigrator ? null : latestMigrator;
                operationDescription =
                    new MigrationOperationDescription(MigrationOperationTypes.CreateDefaultAndUpgradeToTarget,
                                                      currentVersion,
                                                      startMigrator != null ? startMigrator.Version : null,
                                                      targetMigrator != null ? targetMigrator.Version : null);
            }
            else
            {
                Migrator startMigrator = GetMigratorAfterVersion(currentVersion);
                if (startMigrator != null)
                {
                    Migrator targetMigrator = GetLatestVersionMigrator();
                    MainConsole.Instance.InfoFormat("[Migrator]: New migration script for {0} found", migratorName);
                    MainConsole.Instance.CleanInfoFormat("            Depending upon the amount of {0} data, this process may take quite a while", migratorName);
                    MainConsole.Instance.CleanInfo("             You may also see warnings and possible timeout errors until this proccess is completed");
                    MainConsole.Instance.CleanInfo("");

                    operationDescription = new MigrationOperationDescription(MigrationOperationTypes.UpgradeToTarget,
                                                                             currentVersion, startMigrator.Version,
                                                                             targetMigrator.Version);
                }
                else
                {
                    operationDescription = new MigrationOperationDescription(MigrationOperationTypes.DoNothing,
                                                                             currentVersion);
                }
            }
        }
Ejemplo n.º 5
0
        public void DetermineOperation()
        {
            if (migratorName == "")
            {
                return;
            }
            executed = false;
            Version currentVersion = genericData.GetUniverseVersion(migratorName);

            //if there is no Universe version, this is likely an entirely new installation
            if (currentVersion == null)
            {
                Migrator defaultMigrator = GetHighestVersionMigratorThatCanProvideDefaultSetup();
                currentVersion = defaultMigrator.Version;
                Migrator startMigrator  = GetMigratorAfterVersion(defaultMigrator.Version);
                var      latestMigrator = GetLatestVersionMigrator();
                Migrator targetMigrator = defaultMigrator == latestMigrator ? null : latestMigrator;
                operationDescription =
                    new MigrationOperationDescription(MigrationOperationTypes.CreateDefaultAndUpgradeToTarget,
                                                      currentVersion,
                                                      startMigrator != null ? startMigrator.Version : null,
                                                      targetMigrator != null ? targetMigrator.Version : null);
            }
            else
            {
                Migrator startMigrator = GetMigratorAfterVersion(currentVersion);
                if (startMigrator != null)
                {
                    Migrator targetMigrator = GetLatestVersionMigrator();
                    operationDescription = new MigrationOperationDescription(MigrationOperationTypes.UpgradeToTarget,
                                                                             currentVersion, startMigrator.Version,
                                                                             targetMigrator.Version);
                }
                else
                {
                    operationDescription = new MigrationOperationDescription(MigrationOperationTypes.DoNothing,
                                                                             currentVersion);
                }
            }
        }