Module: Lore::Migration
- Included in:
- Model
- Defined in:
- lib/lore/migration.rb
Overview
Usage:
Using auto-bootstrap of models:
class My_Model < Lore::Model
extend Lore::Migration
table :my_model, :public
primary_key :key_a, :key_a_seq
primary_key :key_b
has_attributes {
:foo, Lore::Type.integer, { :unique => true, :default => 1 }
:bar, Lore::Type.integer, { :not_null => true, :check => 'bar < 1000' }
}
def self.up
bootstrap()
My_Model.create(:foo => 23, :bar => 123)
end
end
Instance Method Summary collapse
Instance Method Details
#bootstrap ⇒ Object
41 42 43 |
# File 'lib/lore/migration.rb', line 41 def bootstrap @factory.build_table end |
#has_attributes(attrib_hash) ⇒ Object
30 31 32 |
# File 'lib/lore/migration.rb', line 30 def has_attributes(attrib_hash) @model_schema = attrib_hash end |
#update_schema ⇒ Object
34 35 36 37 38 39 |
# File 'lib/lore/migration.rb', line 34 def update_schema @factory = Model_Factory.new(self.class.to_s) @model_schema.each_pair { |attrib_name, attrib_props| @factory.add_attribute(attrib_name.to_s, attrib_props) } end |