Module: UsesguidMigrations::ActiveRecordExtensions::ConnectionAdapters::SchemaStatements
- Defined in:
- lib/usesguid_migrations/active_record_extensions/connection_adapters/schema_statements.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_column_with_lfe_usesguid_migrations(table_name, column_name, type, options = {}) ⇒ Object
- #create_table_with_lfe_usesguid_migrations(table_name, options = {}) {|table_definition| ... } ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/schema_statements.rb', line 4 def self.included( base ) base.module_eval do alias_method_chain :create_table, :lfe_usesguid_migrations alias_method_chain :add_column, :lfe_usesguid_migrations end end |
Instance Method Details
#add_column_with_lfe_usesguid_migrations(table_name, column_name, type, options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/schema_statements.rb', line 26 def add_column_with_lfe_usesguid_migrations( table_name, column_name, type, ={} ) return add_column_without_lfe_usesguid_migrations( table_name, column_name, type, ) unless %w(guid guid_fk).include?( type.to_s ) column_name = (type.to_s == 'guid_fk' && column_name) ? "#{column_name}_id" : column_name uses_guid_add_column( table_name, column_name, type, ) end |
#create_table_with_lfe_usesguid_migrations(table_name, options = {}) {|table_definition| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/schema_statements.rb', line 11 def create_table_with_lfe_usesguid_migrations( table_name, ={} ) table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new( self ) if [:guid] == false table_definition.primary_key( [:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless [:id] == false else table_definition.guid_primary_key( [:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless [:id] == false end yield table_definition drop_table( table_name, ) if [:force] && table_exists?( table_name ) usesguid_create_table( table_name, table_definition, ) end |