Module: Polymorpheus::ConnectionAdapters::MysqlAdapter
- Defined in:
- lib/polymorpheus/mysql_adapter.rb
Constant Summary collapse
- INSERT =
'INSERT'
- UPDATE =
'UPDATE'
Instance Method Summary collapse
- #add_polymorphic_constraints(table, columns, options = {}) ⇒ Object
-
#add_polymorphic_triggers(table, column_names) ⇒ Object
DO NOT USE THIS METHOD DIRECTLY.
- #remove_polymorphic_constraints(table, columns, options = {}) ⇒ Object
- #triggers ⇒ Object
Instance Method Details
#add_polymorphic_constraints(table, columns, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/polymorpheus/mysql_adapter.rb', line 62 def add_polymorphic_constraints(table, columns, ={}) column_names = columns.keys.sort add_polymorphic_triggers(table, column_names) .symbolize_keys! if [:unique].present? poly_create_indexes(table, column_names, Array([:unique])) end column_names.each do |col_name| ref_table, ref_col = columns[col_name].to_s.split('.') = { :column => col_name, :name => "#{table}_#{col_name}_fk", :primary_key => (ref_col || 'id' ) }.merge(generate_constraints()) add_foreign_key(table, ref_table, **) end end |
#add_polymorphic_triggers(table, column_names) ⇒ Object
DO NOT USE THIS METHOD DIRECTLY
it will not create the foreign key relationships you want. the only reason it is here is because it is used by the schema dumper, since the schema dump will contains separate statements for foreign keys, and we don’t want to duplicate those
102 103 104 105 106 |
# File 'lib/polymorpheus/mysql_adapter.rb', line 102 def add_polymorphic_triggers(table, column_names) column_names.sort! poly_drop_triggers(table, column_names) poly_create_triggers(table, column_names) end |
#remove_polymorphic_constraints(table, columns, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/polymorpheus/mysql_adapter.rb', line 81 def remove_polymorphic_constraints(table, columns, = {}) poly_drop_triggers(table, columns.keys.sort) columns.each do |(col, reference)| remove_foreign_key table, :column => col, :name => "#{table}_#{col}_fk" end if [:unique].present? poly_remove_indexes(table, columns.keys, Array([:unique])) end end |
#triggers ⇒ Object
91 92 93 |
# File 'lib/polymorpheus/mysql_adapter.rb', line 91 def triggers execute("show triggers").collect {|t| Polymorpheus::Trigger.new(t) } end |