Beispiel #1
0
        /// <summary>
        /// Looks for a file named DatabaseDefaults.sql.  If it exists it runs it.  The purpose of this file is to create default data in the database.  This will only be ran one time on initial creation of the database.
        /// </summary>
        private InstallResult BuildDatabaseDefaults()
        {
            OnBeforeDatabaseDefaults(EventArgs.Empty);
            InstallResult result = new InstallResult();

            Logger.Info("Creating initial database defaults from {0}.", INITIAL_DATABASE_DEFAULTS_FILENAME);

            var script = UpdateScript.FromScriptName(INITIAL_DATABASE_DEFAULTS_FILENAME, ExecutingAssembly);

            if (script.FileContents == null)
            {
                string message = string.Format("Initial database defaults file {0} could not be found.  Database schema creation was successful but the defaults were not loaded into the database.  This will cause a problem with login and other initial date the database is expecting.  Try to to run it again in SQL manager if possible.", script.FullNamespaceName);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
                return(result);
            }

            var dbCreateResuls = RunSingleScript(script);

            if (dbCreateResuls.Status == SchemaChange.Status_Failed)
            {
                string message = string.Format("Building the initial database defaults for this database has failed. There was a problem while running the update file {0}. Here is the error: {1}. This will cause a problem with login and other initial date the database is expecting.  Try to to run it again in SQL manager if possible.", script.Name, dbCreateResuls.ScriptErrors);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
            }

            Logger.Info("Initial database defaults created!");

            OnAfterDatabaseDefaults(EventArgs.Empty);
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Looks for the file named DatabaseBaseline.sql and runs it on a blank database.
        /// </summary>
        private InstallResult BuildInitialSchema()
        {
            OnBeforeInitialSchema(EventArgs.Empty);

            InstallResult result = new InstallResult();

            Logger.Info("Creating initial database schema from {0}.", INITIAL_DATABASE_SCHEMA_FILENAME);

            var script = UpdateScript.FromScriptName(INITIAL_DATABASE_SCHEMA_FILENAME, ExecutingAssembly);

            if (script.FileContents == null)
            {
                string message = string.Format("The initial schema creation for this database has failed. The {0} file could not be found at {1}.", INITIAL_DATABASE_SCHEMA_FILENAME, script.FullNamespaceName);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
                return(result);
            }

            var dbCreateResuls = RunSingleScript(script);

            if (dbCreateResuls.Status == SchemaChange.Status_Failed)
            {
                string message = string.Format("The initial schema creation for this database has failed. There was a problem while running the update file {0}. Here is the error: {1} ", script.Name, dbCreateResuls.ScriptErrors);
                Logger.Error(message);
                result.Success = false;
                result.SetMessage(message);
            }

            Logger.Info("Initial database schema created!");

            OnAfterInitialSchema(EventArgs.Empty);
            return(result);
        }
Beispiel #3
0
        private SchemaChange RunSingleScript(string scriptName)
        {
            var updateScript = UpdateScript.FromScriptName(scriptName, ExecutingAssembly);

            return(RunSingleScript(updateScript));
        }