Sha256: b5ea0957e19a4e0eb11cc8fa68e94c701088571588308c233557012df322709a

Contents?: true

Size: 814 Bytes

Versions: 17

Compression:

Stored size: 814 Bytes

Contents

module LolDba
  class Migration
    attr_accessor :full_name

    def initialize(migration_file)
      self.full_name = File.basename(migration_file, ".rb")
      require Rails.root.join(migration_file)
    end

    def number
      /^(\d+)_(.*)$/.match(full_name)[1]
    end

    def name
      /^(\d+)_(.*)$/.match(full_name)[2]
    end

    def to_s
      full_name
    end

    def migration_class
      name.camelize.split(".")[0].constantize
    end

    def up
      migration_class.migrate(:up)
      connection.execute("INSERT INTO schema_migrations (version) VALUES (#{number})")
    end

    def down
      migration_class.migrate(:down)
      connection.execute("DELETE FROM schema_migrations WHERE version = #{number}")
    end

    def connection
      ActiveRecord::Base.connection
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
lol_dba-2.1.5 lib/lol_dba/migration.rb
lol_dba-2.1.4 lib/lol_dba/migration.rb
lol_dba-2.1.3 lib/lol_dba/migration.rb
lol_dba-2.1.2 lib/lol_dba/migration.rb
lol_dba-2.1.1 lib/lol_dba/migration.rb
lol_dba-2.1.0 lib/lol_dba/migration.rb
lol_dba-2.0.3 lib/lol_dba/migration.rb
lol_dba-2.0.2 lib/lol_dba/migration.rb
lol_dba-2.0.1 lib/lol_dba/migration.rb
lol_dba-2.0.0 lib/lol_dba/migration.rb
lol_dba-1.6.7 lib/lol_dba/migration.rb
lol_dba-1.6.6 lib/lol_dba/migration.rb
lol_dba-1.6.5 lib/lol_dba/migration.rb
lol_dba-1.6.4 lib/lol_dba/migration.rb
lol_dba-1.6.3 lib/lol_dba/migration.rb
lol_dba-1.6.2 lib/lol_dba/migration.rb
lol_dba-1.6.1 lib/lol_dba/migration.rb