Class: Volt::MigrationRunner

Inherits:
Object
  • Object
show all
Defined in:
app/sql/lib/migration_runner.rb

Instance Method Summary collapse

Instance Method Details

#__run__Object



6
# File 'app/sql/lib/migration_runner.rb', line 6

alias_method :__run__, :run

#add_version(version) ⇒ Object



30
31
32
# File 'app/sql/lib/migration_runner.rb', line 30

def add_version(version)
  raw_db[:migration_versions].insert(version: version)
end

#all_versionsObject



42
43
44
# File 'app/sql/lib/migration_runner.rb', line 42

def all_versions
  raw_db.from(:migration_versions).all.map {|v| v[:version] }
end

#ensure_migration_versions_tableObject



21
22
23
24
25
26
27
28
# File 'app/sql/lib/migration_runner.rb', line 21

def ensure_migration_versions_table
  if !raw_db.tables || !raw_db.tables.include?(:migration_versions)
    raw_db.create_table(:migration_versions) do
      primary_key :id
      Fixnum :version, unique: true
    end
  end
end

#has_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/sql/lib/migration_runner.rb', line 34

def has_version?(version)
  raw_db.from(:migration_versions).where(version: version).count > 0
end

#raw_dbObject



17
18
19
# File 'app/sql/lib/migration_runner.rb', line 17

def raw_db
  @raw_db ||= Volt.current_app.database.raw_db
end

#remove_version(version) ⇒ Object



38
39
40
# File 'app/sql/lib/migration_runner.rb', line 38

def remove_version(version)
  raw_db.from(:migration_versions).where(version: version).delete
end

#run(direction = :up, until_version = nil) ⇒ Object



8
9
10
11
12
13
14
15
# File 'app/sql/lib/migration_runner.rb', line 8

def run(direction=:up, until_version=nil)
  # reconcile after run in production
  # if Volt.env.production?
  #   Volt.current_app.database.reconcile!
  # end

  __run__(direction, until_version)
end