Class: BazaMigrations::Commands::CreateTable
- Defined in:
- lib/baza_migrations/commands/create_table.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #belongs_to(name, args = {}) ⇒ Object
- #changed_rollback_sql ⇒ Object
- #datetime(name, args = {}) ⇒ Object
-
#initialize(name) ⇒ CreateTable
constructor
A new instance of CreateTable.
- #integer(name, args = {}) ⇒ Object
- #sql ⇒ Object
- #string(name, args = {}) ⇒ Object
- #text(name, args = {}) ⇒ Object
- #timestamps(args = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(name) ⇒ CreateTable
Returns a new instance of CreateTable.
2 3 4 5 6 7 |
# File 'lib/baza_migrations/commands/create_table.rb', line 2 def initialize(name) @name = name @columns = [] @columns << {name: :id, type: :int, autoincr: true, primarykey: true} end |
Instance Method Details
#belongs_to(name, args = {}) ⇒ Object
26 27 28 |
# File 'lib/baza_migrations/commands/create_table.rb', line 26 def belongs_to(name, args = {}) @columns << {name: "#{name}_id", type: :int, null: true}.merge(default_args(args)) end |
#changed_rollback_sql ⇒ Object
38 39 40 |
# File 'lib/baza_migrations/commands/create_table.rb', line 38 def changed_rollback_sql ["DROP TABLE `#{@name}`"] end |
#datetime(name, args = {}) ⇒ Object
30 31 32 |
# File 'lib/baza_migrations/commands/create_table.rb', line 30 def datetime(name, args = {}) @columns << {name: name, type: :datetime}.merge(default_args(args)) end |
#integer(name, args = {}) ⇒ Object
17 18 19 |
# File 'lib/baza_migrations/commands/create_table.rb', line 17 def integer(name, args = {}) @columns << {name: name, type: :int}.merge(default_args(args)) end |
#sql ⇒ Object
34 35 36 |
# File 'lib/baza_migrations/commands/create_table.rb', line 34 def sql db.tables.create(@name, {columns: @columns}, return_sql: true) end |
#string(name, args = {}) ⇒ Object
9 10 11 |
# File 'lib/baza_migrations/commands/create_table.rb', line 9 def string(name, args = {}) @columns << {name: name, type: :string}.merge(default_args(args)) end |
#text(name, args = {}) ⇒ Object
13 14 15 |
# File 'lib/baza_migrations/commands/create_table.rb', line 13 def text(name, args = {}) @columns << {name: name, type: :text}.merge(default_args(args)) end |
#timestamps(args = {}) ⇒ Object
21 22 23 24 |
# File 'lib/baza_migrations/commands/create_table.rb', line 21 def (args = {}) @columns << {name: :created_at, type: :datetime}.merge(default_args(args)) @columns << {name: :updated_at, type: :datetime}.merge(default_args(args)) end |