Class: Reins::Migration::TableDefinition
- Inherits:
-
Object
- Object
- Reins::Migration::TableDefinition
- Defined in:
- lib/reins/migration.rb
Instance Attribute Summary collapse
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
Instance Method Summary collapse
- #column(column_name, type) ⇒ Object
-
#initialize(name) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #references(name) ⇒ Object
- #timestamps ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(name) ⇒ TableDefinition
Returns a new instance of TableDefinition.
128 129 130 131 132 |
# File 'lib/reins/migration.rb', line 128 def initialize(name) @name = name @columns = ["id INTEGER PRIMARY KEY AUTOINCREMENT"] @indexes = [] end |
Instance Attribute Details
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
126 127 128 |
# File 'lib/reins/migration.rb', line 126 def indexes @indexes end |
Instance Method Details
#column(column_name, type) ⇒ Object
140 141 142 |
# File 'lib/reins/migration.rb', line 140 def column(column_name, type) @columns << "#{column_name} #{Reins::Migration::SUPPORTED_TYPES[type.to_sym] || type.to_s.upcase}" end |
#references(name) ⇒ Object
149 150 151 152 |
# File 'lib/reins/migration.rb', line 149 def references(name) column("#{name}_id", :integer) @indexes << [@name, "#{name}_id"] end |
#timestamps ⇒ Object
144 145 146 147 |
# File 'lib/reins/migration.rb', line 144 def column(:created_at, :datetime) column(:updated_at, :datetime) end |
#to_sql ⇒ Object
154 155 156 |
# File 'lib/reins/migration.rb', line 154 def to_sql "CREATE TABLE #{@name} (#{@columns.join(', ')})" end |