Пример #1
0
        public override void Execute(CommandPipelineContext context)
        {
            var database = _configuration.GetDatabaseName();

            var connector = _factory.UseBasicConnector();

            if (!connector.DatabaseExists())
            {
                Logger.InfoFormat("Target database '{0}' not found on instance '{1}', creating...",
                                  _configuration.GetDatabaseName(),
                                  _configuration.GetDatabaseServerName());

                var step = Pipeline.ResolveStep <CleanDatabaseStep>();
                step.Execute(context);
            }

            Logger.InfoFormat("Inspecting schema on database '{0}' for version and history tables...", database);

            if (context.IsSchemaPresent)
            {
                Logger.InfoFormat("Schema version and history tables present on database '{0}'.", database);
            }
            else
            {
                Logger.InfoFormat("Creating version and history tables on database '{0}'...", database);
                ExtractSchemaDefinitionAndApplyToTargetDatabase();
                //CreateVersionInfoTable();
                //CreateScriptsRunInfoTable();
                //CreateScriptsRunErrorInfoTable();
                //CreateScriptsRunDeployInfoTable();
                Logger.InfoFormat("Version and history tables created on database '{0}'.", database);
            }
        }
Пример #2
0
        private bool IsDatabasePresent()
        {
            base.Logger.InfoFormat("Dropping {0} on instance {1} if it exists..",
                                   _configuration.GetDatabaseName(),
                                   _configuration.GetDatabaseServerName());

            var connector = _factory.UseBasicConnector();

            return(connector.DatabaseExists());
        }
Пример #3
0
 public override void Execute(CommandPipelineContext context)
 {
     if (context.AllScriptsRun.Any())
     {
         Logger.InfoFormat("Database '{0}' on instance '{1}' has been updated to version '{2}'.",
                           _configuration.GetDatabaseName(),
                           _configuration.GetDatabaseServerName(),
                           context.ToVersion);
     }
     else
     {
         Logger.InfoFormat("No new or changed scripts found to apply for database '{0}' on  instance '{1}'...",
                           _configuration.GetDatabaseName(),
                           _configuration.GetDatabaseServerName());
     }
 }
Пример #4
0
        public override void Execute(CommandPipelineContext context)
        {
            using (SqlConnection masterConnection = _configuration.GetConnectionToMaster())
                using (SqlCommand createDbCommand = masterConnection.CreateCommand())
                {
                    var database = _configuration.GetDatabaseName();

                    var statement = new StringBuilder();
                    statement
                    .AppendFormat("ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;", database)
                    .AppendLine()
                    .AppendFormat("IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'{0}')",
                                  database).AppendLine()
                    .AppendFormat("DROP DATABASE [{0}]", database).AppendLine()
                    .AppendLine()
                    .AppendFormat("CREATE DATABASE [{0}]", database).AppendLine()
                    .AppendFormat("ALTER DATABASE [{0}] SET ALLOW_SNAPSHOT_ISOLATION ON", database)
                    .AppendLine()
                    .AppendFormat("ALTER DATABASE [{0}] SET RECOVERY SIMPLE", database).AppendLine();

                    createDbCommand.CommandText = statement.ToString();
                    createDbCommand.ExecuteNonQuery();
                    masterConnection.Close();
                }
        }
Пример #5
0
        public void Execute(string currentVersion, string desiredVersion)
        {
            ExecuteVersioningStrategy(currentVersion, desiredVersion);

            if (FromVersion == ToVersion)
            {
                Logger.InfoFormat("Database '{0}' is currently at version '{1}'.",
                                  _configuration.GetDatabaseName(),
                                  currentVersion);
            }
            else
            {
                Logger.InfoFormat("Attempting to upgrade database '{0}' from version '{1}' to '{2}'...",
                                  _configuration.GetDatabaseName(),
                                  FromVersion,
                                  ToVersion);
            }
        }
Пример #6
0
        private bool IsDatabasePresent()
        {
            var result = false;

            Logger.InfoFormat("Creating {0} on instance {1} if it does not exist..",
                              _configuration.GetDatabaseName(),
                              _configuration.GetDatabaseServerName());

            try
            {
                var connector = _factory.UseBasicConnector();
                result = connector.DatabaseExists();
            }
            catch
            {
            }

            return(result);
        }
Пример #7
0
        public override void Execute(CommandPipelineContext context)
        {
            Logger.InfoFormat(
                "Executing db-advance v{0} against instance {1} for database {2}...",
                GetType().Assembly.GetName().Version.ToString(),
                _configuration.GetDatabaseServerName(),
                _configuration.GetDatabaseName());

            Logger.InfoFormat(
                "Looking in current path '{0}' for all scripts to run...",
                context.Options.ScriptsPath);
        }
Пример #8
0
        private void BackUpDatabaseToSpecifiedDirectory(CommandPipelineContext context)
        {
            var timestamp       = DateTime.Now.ToString("hhmmss");
            var backupDirectory = context.Options.BackupDirectory;

            var backupFile = Path.Combine(backupDirectory,
                                          string.Format("{0} - Full Backup - {1}.bak", timestamp, _configuration.GetDatabaseName()));

            var statement =
                string.Format(
                    @"BACKUP DATABASE [{0}] TO DISK = N'{1}' WITH NOFORMAT, INIT, NAME = N'{0} - Full Backup - {2}', SKIP, NOREWIND, NOUNLOAD, STATS = 10",
                    _configuration.GetDatabaseName(), backupFile, timestamp);

            Logger.InfoFormat("Backing up database '{0}' to location '{1}'...",
                              _configuration.GetDatabaseName(), backupFile);

            var connector = _factory.UseSqlCmdConnector();

            connector.Apply(statement);

            Logger.InfoFormat("Database '{0}' backed up to location '{1}' with restore set date/time stamp of '{2}'.",
                              _configuration.GetDatabaseName(), backupDirectory, timestamp);
        }
Пример #9
0
        public override void Execute(CommandPipelineContext context)
        {
            Logger.InfoFormat("Creating/re-creating database '{0}' on instance '{1}'...",
                              _configuration.GetDatabaseName(),
                              _configuration.GetDatabaseServerName());

            CleanTargetDatabaseViaDropAndCreate(context);

            Logger.InfoFormat("Database '{0}' on instance '{1}' created.",
                              _configuration.GetDatabaseName(),
                              _configuration.GetDatabaseServerName());
        }
Пример #10
0
        public override void Execute(CommandPipelineContext context)
        {
            Logger.InfoFormat("Database '{0}' on instance '{1}' is currently at version {2}.",
                              _configuration.GetDatabaseName(),
                              _configuration.GetDatabaseServerName(),
                              GetCurrentVersionNumber());

            if (!string.IsNullOrEmpty(context.Options.Environment))
            {
                Logger.InfoFormat("'{0}' tag found for isolating environment specific scripts...",
                                  context.Options.Environment);
            }

            if (context.Options.Warn == true)
            {
                Logger.InfoFormat("Warning is set for scripts that have changed between runs.");
            }
        }