module Postjob::Migrations
Constants
- CHANNEL
- CLIENT_VERSION
- DEFAULT_QUEUE
- SCHEMA_NAME
- SQL
Public Instance Methods
migrate!()
click to toggle source
# File lib/postjob/migrations.rb, line 24 def migrate! SQL.exec "CREATE SCHEMA IF NOT EXISTS #{SCHEMA_NAME}" Dir.glob(__FILE__.gsub(/\.rb$/, "/**/*.{sql,rb}")).sort.each do |file| run_migration file end end
unmigrate!()
click to toggle source
# File lib/postjob/migrations.rb, line 17 def unmigrate! ::Postjob::Host.clear_storage SQL.exec "SET client_min_messages TO WARNING" SQL.exec "DROP SCHEMA IF EXISTS #{SCHEMA_NAME} CASCADE" end
Private Instance Methods
run_migration(file)
click to toggle source
# File lib/postjob/migrations.rb, line 34 def run_migration(file) Postjob.logger.debug "[postjob] Running migration in #{file}" case file when /\.rb$/ then run_migration_ruby(file) when /\.sql$/ then run_migration_sql(file) end end
run_migration_ruby(file)
click to toggle source
# File lib/postjob/migrations.rb, line 43 def run_migration_ruby(file) eval File.read(file) end
run_migration_sql(file)
click to toggle source
# File lib/postjob/migrations.rb, line 47 def run_migration_sql(file) sql = File.read(file) sql.gsub!(/\{([_A-Za-z0-9+]+)\}/) { |_| const_get(Regexp.last_match(1)) } SQL.exec sql end