Module: GlobalUid::MigrationExtension
- Defined in:
- lib/global_uid/migration_extension.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_table_with_global_uid(name, options = {}, &blk) ⇒ Object
- #drop_table_with_global_uid(name, options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 |
# File 'lib/global_uid/migration_extension.rb', line 3 def self.included(base) base.alias_method_chain :create_table, :global_uid base.alias_method_chain :drop_table, :global_uid end |
Instance Method Details
#create_table_with_global_uid(name, options = {}, &blk) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/global_uid/migration_extension.rb', line 8 def create_table_with_global_uid(name, = {}, &blk) uid_enabled = !(GlobalUid::Base.[:disabled] || [:use_global_uid] == false) # rules for stripping out auto_increment -- enabled, not dry-run, and not a "PK-less" table remove_auto_increment = uid_enabled && !GlobalUid::Base.[:dry_run] && !([:id] == false) if remove_auto_increment old_id_option = [:id] .merge!(:id => false) end if uid_enabled id_table_name = [:global_uid_table] || GlobalUid::Base.id_table_from_name(name) GlobalUid::Base.create_uid_tables(id_table_name, ) end create_table_without_global_uid(name, ) { |t| if remove_auto_increment # need to honor specifically named tables id_column_name = (old_id_option || :id) t.column id_column_name, "int(10) NOT NULL PRIMARY KEY" end blk.call(t) if blk } end |
#drop_table_with_global_uid(name, options = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/global_uid/migration_extension.rb', line 34 def drop_table_with_global_uid(name, = {}) if !GlobalUid::Base.[:disabled] && [:use_global_uid] == true id_table_name = [:global_uid_table] || GlobalUid::Base.id_table_from_name(name) GlobalUid::Base.drop_uid_tables(id_table_name,) end drop_table_without_global_uid(name) end |