Class: Lhm::Adapter
- Inherits:
-
Object
- Object
- Lhm::Adapter
- Defined in:
- lib/lhm/adapter.rb
Overview
Translates Lhm DSL to ActiveRecord’s one, so Lhm migrations will now go through Percona as well, without any modification on the migration’s code
Instance Method Summary collapse
-
#add_column(column_name, definition) ⇒ Object
Adds the specified column through ActiveRecord.
-
#add_index(columns, index_name = nil) ⇒ Object
Adds an index in the specified columns through ActiveRecord.
-
#add_unique_index(columns, index_name = nil) ⇒ Object
Adds a unique index on the given columns, with the provided name if passed.
-
#change_column(column_name, definition) ⇒ Object
Change the column to use the provided definition, through ActiveRecord.
-
#initialize(migration, table_name) ⇒ Adapter
constructor
Constructor.
-
#remove_column(column_name) ⇒ Object
Removes the specified column through ActiveRecord.
-
#remove_index(columns, index_name = nil) ⇒ Object
Removes the index in the given columns or by its name.
-
#rename_column(old_name, new_name) ⇒ Object
Renames the old_name column to new_name by using ActiveRecord.
Constructor Details
#initialize(migration, table_name) ⇒ Adapter
Constructor
15 16 17 18 |
# File 'lib/lhm/adapter.rb', line 15 def initialize(migration, table_name) @migration = migration @table_name = table_name end |
Instance Method Details
#add_column(column_name, definition) ⇒ Object
Adds the specified column through ActiveRecord
24 25 26 27 |
# File 'lib/lhm/adapter.rb', line 24 def add_column(column_name, definition) attributes = column_attributes(column_name, definition) migration.add_column(*attributes) end |
#add_index(columns, index_name = nil) ⇒ Object
Adds an index in the specified columns through ActiveRecord. Note you can provide a name as well
41 42 43 44 |
# File 'lib/lhm/adapter.rb', line 41 def add_index(columns, index_name = nil) = { name: index_name } if index_name migration.add_index(table_name, columns, || {}) end |
#add_unique_index(columns, index_name = nil) ⇒ Object
Adds a unique index on the given columns, with the provided name if passed
80 81 82 83 84 85 |
# File 'lib/lhm/adapter.rb', line 80 def add_unique_index(columns, index_name = nil) = { unique: true } .merge!(name: index_name) if index_name migration.add_index(table_name, columns, ) end |
#change_column(column_name, definition) ⇒ Object
Change the column to use the provided definition, through ActiveRecord
63 64 65 66 |
# File 'lib/lhm/adapter.rb', line 63 def change_column(column_name, definition) attributes = column_attributes(column_name, definition) migration.change_column(*attributes) end |
#remove_column(column_name) ⇒ Object
Removes the specified column through ActiveRecord
32 33 34 |
# File 'lib/lhm/adapter.rb', line 32 def remove_column(column_name) migration.remove_column(table_name, column_name) end |
#remove_index(columns, index_name = nil) ⇒ Object
Removes the index in the given columns or by its name
50 51 52 53 54 55 56 57 |
# File 'lib/lhm/adapter.rb', line 50 def remove_index(columns, index_name = nil) = if index_name { name: index_name } else { column: columns } end migration.remove_index(table_name, ) end |
#rename_column(old_name, new_name) ⇒ Object
Renames the old_name column to new_name by using ActiveRecord
72 73 74 |
# File 'lib/lhm/adapter.rb', line 72 def rename_column(old_name, new_name) migration.rename_column(table_name, old_name, new_name) end |