Class: ForceSchema::Schema
- Inherits:
-
Object
- Object
- ForceSchema::Schema
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/force_schema/schema.rb
Constant Summary collapse
- MAX_INDEX_NAME_LENGTH =
mysql
32
Instance Attribute Summary collapse
-
#active_record ⇒ Object
readonly
Returns the value of attribute active_record.
-
#create_table_options ⇒ Object
Returns the value of attribute create_table_options.
Class Method Summary collapse
Instance Method Summary collapse
- #index(columns, index_options = {}) ⇒ Object
-
#initialize(active_record) ⇒ Schema
constructor
A new instance of Schema.
- #run ⇒ Object
Constructor Details
#initialize(active_record) ⇒ Schema
Returns a new instance of Schema.
26 27 28 |
# File 'lib/force_schema/schema.rb', line 26 def initialize(active_record) @active_record = active_record end |
Instance Attribute Details
#active_record ⇒ Object (readonly)
Returns the value of attribute active_record.
23 24 25 |
# File 'lib/force_schema/schema.rb', line 23 def active_record @active_record end |
#create_table_options ⇒ Object
Returns the value of attribute create_table_options.
24 25 26 |
# File 'lib/force_schema/schema.rb', line 24 def @create_table_options end |
Class Method Details
.suggest_index_name(active_record, columns, index_options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/force_schema/schema.rb', line 10 def suggest_index_name(active_record, columns, = {}) return [:name] if .has_key? :name default_name = 'index_' + ::Array.wrap(columns).join('_and_') #active_record.connection.index_name(active_record.table_name, index_options.merge(:column => columns)) if default_name.length < MAX_INDEX_NAME_LENGTH default_name else default_name[0..MAX_INDEX_NAME_LENGTH-11] + ::Zlib.crc32(default_name).to_s end end |
Instance Method Details
#index(columns, index_options = {}) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/force_schema/schema.rb', line 52 def index(columns, = {}) = .symbolize_keys columns = ::Array.wrap columns index_name = Schema.suggest_index_name active_record, columns, index_unique = .has_key?(:unique) ? [:unique] : true ideal_indexes.push ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, index_name, index_unique, columns) nil end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/force_schema/schema.rb', line 61 def run _create_table _set_primary_key _remove_columns _add_columns _remove_indexes _add_indexes nil end |