public bool run_sql(string sql_to_run, string script_name, bool run_this_script_once, bool run_this_script_every_time, long version_id, Environment environment, string repository_version, string repository_path, ConnectionType connection_type)
        {
            bool this_sql_ran = false;

            if (this_is_a_one_time_script_that_has_changes_but_has_already_been_run(script_name, sql_to_run, run_this_script_once))
            {
                if (error_on_one_time_script_changes)
                {
                    database.rollback();
                    string error_message = string.Format("{0} has changed since the last time it was run. By default this is not allowed - scripts that run once should never change. To change this behavior to a warning, please set warnOnOneTimeScriptChanges to true and run again. Stopping execution.", script_name);
                    record_script_in_scripts_run_errors_table(script_name, sql_to_run, sql_to_run, error_message, repository_version, repository_path);
                    database.close_connection();
                    throw new Exception(error_message);
                }
                Log.bound_to(this).log_a_warning_event_containing("{0} is a one time script that has changed since it was run.", script_name);
            }

            if (this_is_an_environment_file_and_its_in_the_right_environment(script_name, environment)
                && this_script_should_run(script_name, sql_to_run, run_this_script_once, run_this_script_every_time))
            {
                if (!is_dryrun)
                {
                    Log.bound_to(this).log_an_info_event_containing(" {3} {0} on {1} - {2}.", script_name, database.server_name, database.database_name,
                                            is_baseline ? "BASELINING: Recording" : "Running");
                }
                if (!is_baseline)
                {
                    if (!is_dryrun)
                    {
                foreach (var sql_statement in get_statements_to_run(sql_to_run))
                {
                    try
                    {
                        database.run_sql(sql_statement, connection_type);
                    }
                    catch (Exception ex)
                    {
                        database.rollback();

                        record_script_in_scripts_run_errors_table(script_name, sql_to_run, sql_statement, ex.Message, repository_version, repository_path);
                        database.close_connection();
                        throw;
                            }
                        }
                    }
                    else
                    {
                        Log.bound_to(this).log_a_warning_event_containing(" DryRun: {0} on {1} - {2}.", script_name, database.server_name, database.database_name);
                    }
                }
                if (!is_dryrun)
                {
                record_script_in_scripts_run_table(script_name, sql_to_run, run_this_script_once, version_id);
                this_sql_ran = true;
                }
            }
            else
            {
                Log.bound_to(this).log_an_info_event_containing(" Skipped {0} - {1}.", script_name, run_this_script_once ? "One time script" : "No changes were found to run");
            }

            return this_sql_ran;
        }
        public bool this_is_an_environment_file_and_its_in_the_right_environment(string script_name, Environment environment)
        {
            Log.bound_to(this).log_a_debug_event_containing("Checking to see if {0} is an environment file. We are in the {1} environment.", script_name, environment.name);
            if (!script_name.to_lower().Contains(".env."))
            {
                // return true because this is NOT an environment file for the next check
                return true;
            }

            bool environment_file_is_in_the_right_environment = false;

            if (script_name.to_lower().StartsWith(environment.name.to_lower() + "."))
            {
                environment_file_is_in_the_right_environment = true;
            }

            if (script_name.to_lower().Contains("." + environment.name.to_lower() + "."))
            {
                environment_file_is_in_the_right_environment = true;
            }

            Log.bound_to(this).log_an_info_event_containing(" {0} is an environment file. We are in the {1} environment. This will{2} run based on this check.",
                                                            script_name, environment.name, environment_file_is_in_the_right_environment ? string.Empty : " NOT");

            return environment_file_is_in_the_right_environment;
        }
        public bool this_script_is_new_or_updated(string script_name, string sql_to_run, Environment environment)
        {
            if (!this_is_an_environment_file_and_its_in_the_right_environment(script_name, environment))
                return false;

            if (this_script_has_run_already(script_name)
                   && !this_script_has_changed_since_last_run(script_name, sql_to_run))
                return false;

            return true;
        }