lib/pg_migrate/migrator.rb in pg_migrate-0.1.0 vs lib/pg_migrate/migrator.rb in pg_migrate-0.1.1
- old
+ new
@@ -16,41 +16,34 @@
# 'migrate' attempt to migrate your database based on the contents of your built manifest
# The manifest_path argument should point to your manifest
# manifest_path = the directory containing your 'manifest' file, 'up' directory, 'down' directory, 'test' directory
# this method will throw an exception if anything goes wrong (such as bad SQL in the migrations themselves)
-
def migrate(manifest_path)
@manifest_path = manifest_path
- if !@connection_hash[:pgconn].nil?
- @conn = @connection_hash[:pgconn]
- elsif !@connection_hash[:connstring].nil?
- @conn = PG::Connection.open(@connection_hash[:connstring])
- else
- @conn = PG::Connection.open(@connection_hash)
- end
+ @conn = Util::get_conn(@connection_hash)
# this is used to record the version of the 'migrator' in the pg_migrate table
@conn.exec("SET application_name = 'pg_migrate_ruby-#{PgMigrate::VERSION}'")
# load the manifest, and version of the builder that made it
process_manifest()
# execute the migrations
- run_migrations()
+ run_migrations(@manifest)
end
# load the manifest's migration declarations, and validate that each migration points to a real file
def process_manifest
@manifest, @builder_version = @manifest_reader.load_output_manifest(@manifest_path)
@manifest_reader.validate_migration_paths(@manifest_path, @manifest)
end
# run all necessary migrations
- def run_migrations
+ def run_migrations(manifest)
# run bootstrap before user migrations to prepare database
run_bootstrap
# loop through the manifest, executing migrations in turn
@@ -66,10 +59,10 @@
execute_migration('bootstrap.sql', bootstrap)
end
# execute a single migration by loading it's statements from file, and then executing each
def execute_migration(name, filepath)
- @log.debug "executing migration #{filepath}"
+ @log.info "executing migration #{filepath}"
statements = @sql_reader.load_migration(filepath)
if statements.length == 0
raise 'no statements found in migration #{filepath}'
end