Module: Migration

Defined in:
lib/jungle_path/migration/migration.rb

Class Method Summary collapse

Class Method Details

.run(schema_module, db, version = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jungle_path/migration/migration.rb', line 6

def self.run schema_module, db, version=nil
	Sequel.extension :migration

	db.base.loggers << Logger.new($stdout)
	db.base.identifier_input_method = :downcase
	version = schema_module.version unless version
	path = schema_module.migrations_path
	display_version = version || "'latest available'"

	puts "Migrating database to version: #{display_version} on #{db.config.host}.#{db.config.name}:#{db.config.port}."
	puts "Using migration files at: #{path}"

	if JunglePath::DBAccess::Meta::DB.exists? db.config # todo: fix for sql server!
		# migrate to current or passed version.
		if version
			Sequel::Migrator.run(db.base, path, target: version)
		else
			Sequel::Migrator.run(db.base, path)
		end
	else
		# create from scratch and set the version in the new db.
		puts "Database does not exist, run zcreatedb.rb and then zbootstrapdata.rb..."
		puts "Write some code to create the schema_info table with integer column version and set the version! This table should always have only one row."
	end
end