class PhilColumns::Activerecord::Migrator

Public Instance Methods

clear_migrations_table() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 21
def clear_migrations_table
  return unless ActiveRecord::Base.connection.table_exists?( schema_migrations_table_name )

  case connection_config[:adapter]
    when 'sqlite', 'sqlite3'
      connection.execute("DELETE FROM #{table_name}")
      connection.execute("DELETE FROM sqlite_sequence where name='#{table_name}'")
    else
      ActiveRecord::Base.connection.execute( "TRUNCATE #{schema_migrations_table_name}" )
  end

  connection.execute( 'VACUUM' ) if connection_config[:adapter] == 'sqlite3'
end
connection() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 39
def connection
  ActiveRecord::Base::connection
end
connection_config() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 43
def connection_config
  connection.instance_variable_get( '@config' )
end
down( version=0 ) click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 9
def down( version=0 )
  silence_streams do
    ActiveRecord::Migrator.down( ActiveRecord::Migrator.migrations_path, version )
  end
end
drop_table( table ) click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 53
def drop_table( table )
  silence_streams do
    if ActiveRecord::Migration.table_exists?( table )
      ActiveRecord::Migration.drop_table( table )
    end
  end
end
drop_tables() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 47
def drop_tables
  tables.each do |table|
    drop_table( table )
  end
end
exclude_tables() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 83
def exclude_tables
  [
    schema_migrations_table_name,
    'schema_seeds'
  ]
end
latest_version() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 35
def latest_version
  ActiveRecord::Migrator.get_all_versions.sort.last
end
load_schema() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 61
def load_schema
  silence_streams do
    if schema_filepath.exist?
      load( schema_filepath.expand_path )
    end
  end
end
migrations_path() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 69
def migrations_path
  ActiveRecord::Migrator.migrations_path
end
schema_filepath() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 73
def schema_filepath
  Pathname.new( migrations_path.gsub( 'migrate', 'schema.rb' ))
end
schema_migrations_table_name() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 90
def schema_migrations_table_name
  ActiveRecord::Migrator.schema_migrations_table_name
end
tables() click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 77
def tables
  ActiveRecord::Base::connection.
                      tables.
                      reject { |t| exclude_tables.include?( t ) }
end
up( version=nil ) click to toggle source
# File lib/phil_columns/activerecord/migrator.rb, line 15
def up( version=nil )
  silence_streams do
    ActiveRecord::Migrator.up( ActiveRecord::Migrator.migrations_path, version )
  end
end