Esempio n. 1
0
        /// <summary>
        /// Runs all of the necessary offline migrations then applies
        /// the stored code definitions that have changed
        /// </summary>
        public void DeployOffline()
        {
            Plan();
            if (_deploymentPlan.OfflineErrorMessage != null)
            {
                throw new Exception(_deploymentPlan.OfflineErrorMessage);
            }

            var migrationNumberForStoredCode = _deploymentPlan.LastCompletedMigrationNumber;

            if (_deploymentPlan.OfflineMigrations.Any())
            {
                _progressReporter.BeginBlock("Offline Migrations");
                _progressReporter.Report("Running offline migration scripts...");
                foreach (var migrationToRun in _deploymentPlan.OfflineMigrations)
                {
                    _progressReporter.Report($"Running {migrationToRun.Name} ...");
                    _journal.RecordStartMigration(migrationToRun);
                    migrationToRun.Run(_progressReporter);
                    migrationNumberForStoredCode = migrationToRun.MigrationNumber;
                    _journal.RecordCompleteMigration(migrationToRun);
                    _progressReporter.Report("Done.");
                }
                _progressReporter.EndBlock("Offline Migrations");
            }
            else
            {
                _progressReporter.Report("No offline migrations to run.");
            }

            if (_deploymentPlan.HasStoredCodeChanges)
            {
                _progressReporter.BeginBlock("Stored Code Definitions");
                _progressReporter.Report("Running stored code definitions...");
                foreach (var definition in _deploymentPlan.StoredCodeDefinitions)
                {
                    _progressReporter.Report($"Running {definition.Name} ...");
                    definition.Apply(_progressReporter);

                    // Record the fact that we applied that script.
                    _journal.RecordStoredCodeDefinition(definition, migrationNumberForStoredCode);
                    _progressReporter.Report("Done.");
                }
                _progressReporter.EndBlock("Stored Code Definitions");
            }
            else
            {
                _progressReporter.Report("No stored code definitions to update.");
            }
        }