ExecuteDataMigrationScripts() public method

public ExecuteDataMigrationScripts ( ) : DataMigrationReport
return DataMigrationReport
        public void ExecuteGenerators(bool deployDatabaseOnly)
        {
            _deployPackagesLogger.Trace("SQL connection string: " + SqlUtility.MaskPassword(SqlUtility.ConnectionString));
            ValidateDbConnection();

            _deployPackagesLogger.Trace("Preparing Rhetos database.");
            PrepareRhetosDatabase();

            _deployPackagesLogger.Trace("Parsing DSL scripts.");
            int dslModelConceptsCount = _dslModel.Concepts.Count();

            _deployPackagesLogger.Trace("Application model has " + dslModelConceptsCount + " statements.");

            if (deployDatabaseOnly)
            {
                _deployPackagesLogger.Info("Skipped code generators (DeployDatabaseOnly).");
            }
            else
            {
                _deployPackagesLogger.Trace("Compiling DOM assembly.");
                int generatedTypesCount = _domGenerator.Assembly.GetTypes().Length;
                if (generatedTypesCount == 0)
                {
                    _deployPackagesLogger.Error("WARNING: Empty assembly is generated.");
                }
                else
                {
                    _deployPackagesLogger.Trace("Generated " + generatedTypesCount + " types.");
                }

                var generators = GetSortedGenerators();
                foreach (var generator in generators)
                {
                    _deployPackagesLogger.Trace("Executing " + generator.GetType().Name + ".");
                    generator.Generate();
                }
                if (!generators.Any())
                {
                    _deployPackagesLogger.Trace("No additional generators.");
                }
            }

            _deployPackagesLogger.Trace("Cleaning old migration data.");
            _databaseCleaner.RemoveRedundantMigrationColumns();
            _databaseCleaner.RefreshDataMigrationRows();

            _deployPackagesLogger.Trace("Executing data migration scripts.");
            var dataMigrationReport = _dataMigration.ExecuteDataMigrationScripts();

            _deployPackagesLogger.Trace("Upgrading database.");
            try
            {
                _databaseGenerator.UpdateDatabaseStructure();
            }
            catch (Exception ex)
            {
                try
                {
                    _dataMigration.UndoDataMigrationScripts(dataMigrationReport.CreatedTags);
                }
                catch (Exception undoException)
                {
                    _deployPackagesLogger.Error(undoException.ToString());
                }
                ExceptionsUtility.Rethrow(ex);
            }

            _deployPackagesLogger.Trace("Deleting redundant migration data.");
            _databaseCleaner.RemoveRedundantMigrationColumns();
            _databaseCleaner.RefreshDataMigrationRows();

            _deployPackagesLogger.Trace("Uploading DSL scripts.");
            UploadDslScriptsToServer();
        }
Example #2
0
        private List<string> TestExecuteDataMigrationScripts(string[] scriptsDescriptions, string expectedResult, bool skipScriptsWithWrongOrder = false)
        {
            using (var container = new RhetosTestContainer())
            {
                var log = new List<string>();
                container.AddLogMonitor(log);

                var sqlExecuter = container.Resolve<ISqlExecuter>();
                sqlExecuter.ExecuteSql("DELETE FROM Rhetos.DataMigrationScript");

                foreach (string scriptsDescription in scriptsDescriptions)
                {
                    var scriptsProvider = new SimpleScriptsProvider(scriptsDescription);
                    var configuration = new MockConfiguration(new Dictionary<string, object>
                    {
                        { "DataMigration.SkipScriptsWithWrongOrder", skipScriptsWithWrongOrder }
                    });
                    var dataMigration = new DataMigration(sqlExecuter, container.Resolve<ILogProvider>(), scriptsProvider, configuration);
                    dataMigration.ExecuteDataMigrationScripts();
                }

                var report = new List<string>();
                sqlExecuter.ExecuteReader("SELECT Path, Active FROM Rhetos.DataMigrationScript ORDER BY OrderExecuted",
                    reader => report.Add(reader.GetString(0).Replace(".sql", "") + (reader.GetBoolean(1) ? "" : "-")));
                Assert.AreEqual(expectedResult, string.Join(", ", report));

                return log;
            }
        }