Class: SequelRails::Migrations
- Inherits:
-
Object
- Object
- SequelRails::Migrations
- Defined in:
- lib/sequel_rails/migrations.rb
Class Method Summary collapse
- .available_migrations? ⇒ Boolean
- .current_migration ⇒ Object
- .dump_schema_information(opts = {}) ⇒ Object
- .init_migrator ⇒ Object
- .migrate(version = nil) ⇒ Object (also: migrate_up!, migrate_down!)
- .migrations_dir ⇒ Object
- .pending_migrations? ⇒ Boolean
- .previous_migration ⇒ Object
Class Method Details
.available_migrations? ⇒ Boolean
66 67 68 |
# File 'lib/sequel_rails/migrations.rb', line 66 def available_migrations? File.exist?(migrations_dir) && Dir[File.join(migrations_dir, '*')].any? end |
.current_migration ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sequel_rails/migrations.rb', line 42 def current_migration return unless available_migrations? migrator = init_migrator if migrator.respond_to?(:applied_migrations) migrator.applied_migrations.last elsif migrator.respond_to?(:current_version) migrator.current_version end end |
.dump_schema_information(opts = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sequel_rails/migrations.rb', line 26 def dump_schema_information(opts = {}) sql = opts.fetch :sql adapter = SequelRails::Storage.adapter_for(Rails.env) res = '' if available_migrations? migrator = init_migrator res << adapter.schema_information_dump(migrator, sql) end res end |
.init_migrator ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/sequel_rails/migrations.rb', line 70 def init_migrator migrator_class = ::Sequel::Migrator.send(:migrator_class, migrations_dir) migrator_class.new( ::Sequel::Model.db, migrations_dir, allow_missing_migration_files: !!SequelRails.configuration.allow_missing_migration_files ) end |
.migrate(version = nil) ⇒ Object Also known as: migrate_up!, migrate_down!
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sequel_rails/migrations.rb', line 6 def migrate(version = nil) opts = {} opts[:target] = version.to_i if version opts[:allow_missing_migration_files] = !!SequelRails.configuration.allow_missing_migration_files if migrations_dir.directory? ::Sequel::Migrator.run(::Sequel::Model.db, migrations_dir, opts) else relative_path_name = migrations_dir.relative_path_from(Rails.root).to_s raise "The #{relative_path_name} directory doesn't exist, you need to create it." end end |
.migrations_dir ⇒ Object
38 39 40 |
# File 'lib/sequel_rails/migrations.rb', line 38 def migrations_dir Rails.root.join('db/migrate') end |
.pending_migrations? ⇒ Boolean
21 22 23 24 |
# File 'lib/sequel_rails/migrations.rb', line 21 def pending_migrations? return false unless available_migrations? !::Sequel::Migrator.is_current?(::Sequel::Model.db, migrations_dir) end |
.previous_migration ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sequel_rails/migrations.rb', line 54 def previous_migration return unless available_migrations? migrator = init_migrator if migrator.respond_to?(:applied_migrations) migrator.applied_migrations[-2] || '0' elsif migrator.respond_to?(:current_version) migrator.current_version - 1 end end |