Module: Birdbath

Defined in:
lib/birdbath.rb,
lib/birdbath/version.rb

Defined Under Namespace

Modules: Connection Classes: Schema, Table

Constant Summary collapse

VERSION =
"1.3.5"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.migration_dirObject



27
28
29
30
# File 'lib/birdbath.rb', line 27

def self.migration_dir
  root = defined?(RAILS_ROOT) ? RAILS_ROOT : Rails.root.to_s
  @migration_dir || File.expand_path(root + '/db/migrate')
end

.migration_dir=(new_dir) ⇒ Object

sets the directory in which the migrations reside to be run with migrate



35
36
37
# File 'lib/birdbath.rb', line 35

def self.migration_dir=(new_dir)
  @migration_dir = new_dir
end

Instance Method Details

#assert_schema {|schema| ... } ⇒ Object

verifies the schema exactly matches the one specified (schema_info does not have to be specified)

assert_schema do |s|
s.table :dogs do |t|
  t.column :id,   :integer, :default => 2
  t.column :name, :string
end
end

Yields:

  • (schema)


49
50
51
52
53
# File 'lib/birdbath.rb', line 49

def assert_schema
  schema = Schema.new
  yield schema
  schema.verify
end

#assert_table(name) {|table| ... } ⇒ Object

verifies a single table exactly matches the one specified

assert_table :dogs do |t|
t.column :id,   :integer, :default => 2
t.column :name, :string
end

Yields:

  • (table)


63
64
65
66
67
# File 'lib/birdbath.rb', line 63

def assert_table(name)
  table = Table.new(name)
  yield table
  table.verify
end

#drop_all_tablesObject

drops all tables in the database



72
73
74
75
76
# File 'lib/birdbath.rb', line 72

def drop_all_tables
  ActiveRecord::Base.connection.tables.each do |table|
    ActiveRecord::Base.connection.drop_table(table)
  end
end

#migrate(opts = {}) ⇒ Object

executes your migrations

migrate                # same as rake db:migrate

Options are:

  • :version - version to migrate to (same as VERSION=.. option to rake db:migrate)
  • :verbose - print migration status messages to STDOUT, defaults to false


87
88
89
90
91
92
93
94
# File 'lib/birdbath.rb', line 87

def migrate(opts={})
  old_verbose = ActiveRecord::Migration.verbose
  ActiveRecord::Migration.verbose = opts[:verbose].nil? ? false : opts[:verbose]
  version = opts[:version] ? opts[:version].to_i : nil
  ActiveRecord::Migrator.migrate(Birdbath.migration_dir, version)
ensure
  ActiveRecord::Migration.verbose = old_verbose
end