Esempio n. 1
0
        protected override void ProcessRecord()
        {
            try
            {
                if (Global.Connected)
                {
                    throw new InvalidOperationException("Cannot update a database while a connection is open. Call the Disconnect-AcmaEngine cmdlet.");
                }

                DBInstallUpgrader upgrader         = new DBInstallUpgrader(this.ServerName);
                Version           currentdbVersion = upgrader.GetDBVersion(this.DatabaseName);

                if (currentdbVersion == DBInstallUpgrader.DBVersion)
                {
                    Console.WriteLine("The database is already at the current version: " + currentdbVersion.ToString());
                }
                else
                {
                    Console.WriteLine("Performing database upgrade from version " + currentdbVersion.ToString());

                    if (this.ShouldProcess(string.Format("The operation will perform an upgrade of the database to version {0}", DBInstallUpgrader.DBVersion), "Ensure the database has been backed up before proceeding", "Backup database"))
                    {
                        if (this.Force || this.ShouldContinue("Continue with the database upgrade? Please ensure the database has been backed up", "Confirm database update"))
                        {
                            upgrader.UpgradeDB(this.DatabaseName);
                            currentdbVersion = upgrader.GetDBVersion(this.DatabaseName);
                            Console.WriteLine("Database upgraded to version " + currentdbVersion.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Upgrade aborted");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorRecord error = new ErrorRecord(ex, "UnknownError", ErrorCategory.NotSpecified, null);
                ThrowTerminatingError(error);
            }
        }
Esempio n. 2
0
        public static ActionResult InstallUpgradeDB(Session session)
        {
            string sqlServerName      = session.CustomActionData["SqlServerName"];
            string dbName             = session.CustomActionData["DBName"];
            string acmaServiceAccount = session.CustomActionData["AcmaServiceAccount"];

            ValidateInstallUpgradeDBParameters(sqlServerName, dbName);

            DBInstallUpgrader upgrader = new DBInstallUpgrader(sqlServerName);

            if (upgrader.DoesDatabaseExist(dbName))
            {
                session.Log("Database {0} already exists", dbName);
                Version dbVersion = upgrader.GetDBVersion(dbName);
                session.Log("Database version: {0}", dbVersion);

                if (dbVersion < DBInstallUpgrader.DBVersion)
                {
                    session.Log("Database update required to: {0}", DBInstallUpgrader.DBVersion);
                    upgrader.UpgradeDB(dbName);
                    session.Log("Database update complete");
                }
                else if (dbVersion > DBInstallUpgrader.DBVersion)
                {
                    session.Log("Database is newer than binary version: {0}", DBInstallUpgrader.DBVersion);
                    throw new DBVersionException("This version of ACMA cannot be installed because the database is of a newer version than the application. Obtain the latest source files and try again");
                }
                else
                {
                    upgrader.GrantDBRights(dbName, acmaServiceAccount);
                    session.Log("Database is up to date");
                }
            }
            else
            {
                session.Log("Database {0} doesn't exist. Creating and assigning permissions to sync engine account {1}", dbName, acmaServiceAccount);
                upgrader.CreateDB(dbName, acmaServiceAccount);
                session.Log("Database creation complete");
            }

            return(ActionResult.Success);
        }