Module: ReversibilityChecker
- Defined in:
- lib/reversibility_checker.rb,
lib/reversibility_checker/railtie.rb,
lib/reversibility_checker/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
- .current_version(config) ⇒ Object
- .dump(config) ⇒ Object
- .target_versions(config, current_version) ⇒ Object
Class Method Details
.current_version(config) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/reversibility_checker.rb', line 21 def self.current_version(config) return ENV["CURRENT_VERSION"].to_i unless ENV["CURRENT_VERSION"].nil? ActiveRecord::Base.establish_connection(config) version = ActiveRecord::Migrator.current_version ActiveRecord::Base.remove_connection return version end |
.dump(config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/reversibility_checker.rb', line 8 def self.dump(config) case ActiveRecord::Base.schema_format when :ruby buffer = StringIO.new ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, buffer) buffer.string when :sql file = Tempfile.new ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, file.path) file.read end end |
.target_versions(config, current_version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/reversibility_checker.rb', line 31 def self.target_versions(config, current_version) ActiveRecord::Base.establish_connection(config) migration_context = ActiveRecord::Base.connection.migration_context ActiveRecord::Base.remove_connection versions = ActiveRecord::Tasks::DatabaseTasks.migrations_paths.flat_map do |migrations_path| Dir["#{migrations_path}/*.rb"].map do |filepath| migration_context.parse_migration_filename(filepath).first.to_i end end versions.select { |version| version > current_version }.sort end |