Module: MotionRecord::Schema

Defined in:
lib/motion_record/schema.rb,
lib/motion_record/schema/migrator.rb,
lib/motion_record/schema/migration.rb,
lib/motion_record/schema/index_definition.rb,
lib/motion_record/schema/table_definition.rb,
lib/motion_record/schema/column_definition.rb,
lib/motion_record/schema/migrator_definition.rb,
lib/motion_record/schema/migration_definition.rb

Defined Under Namespace

Classes: ColumnDefinition, IndexDefinition, Migration, MigrationDefinition, Migrator, MigratorDefinition, TableDefinition

Class Method Summary collapse

Class Method Details

.up!(options = {}, &block) ⇒ Object

Define and run all pending migrations (should be done during app setup)

options - Hash of configuration options for the SQLite connection

:file - full name of the database file, or :memory for in-memory
        database files (default is "app.sqlite3" in the app's
        `/Library/Application Support` folder)
:debug - set to false to turn off SQL debug logging

Example:

MotionRecord::Schema.up! do
  migration 1, "Create events table" do
    create_table "events" do |t|
      t.text :name, :null => false
      t.text :properties
    end
  end

  migration 2, "Index events table" do
    add_index "events", "name", :unique => true
  end
end


26
27
28
29
30
31
32
33
# File 'lib/motion_record/schema.rb', line 26

def self.up!(options={}, &block)
  ConnectionAdapters::SQLiteAdapter.configure(options)

  definition = Schema::MigratorDefinition.new
  definition.instance_eval &block

  Schema::Migrator.new(definition.migrations).run
end