Class: Volt::MigrationRunner
- Inherits:
-
Object
- Object
- Volt::MigrationRunner
- Defined in:
- app/sql/lib/migration_runner.rb
Instance Method Summary collapse
- #__run__ ⇒ Object
- #add_version(version) ⇒ Object
- #all_versions ⇒ Object
- #ensure_migration_versions_table ⇒ Object
- #has_version?(version) ⇒ Boolean
- #raw_db ⇒ Object
- #remove_version(version) ⇒ Object
- #run(direction = :up, until_version = nil) ⇒ Object
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_versions ⇒ Object
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_table ⇒ Object
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
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_db ⇒ Object
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 |