Example #1
0
        protected override void ProcessRecord()
        {
            try
            {
                DBInstallUpgrader upgrader = new DBInstallUpgrader(this.ServerName);
                upgrader.CreateDB(this.DatabaseName);

                Console.WriteLine("Database created");
            }
            catch (Exception ex)
            {
                ErrorRecord error = new ErrorRecord(ex, "UnknownError", ErrorCategory.NotSpecified, null);
                ThrowTerminatingError(error);
            }
        }
Example #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);
        }