Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/uuidable/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ module Uuidable

# Module adds method to table definition
module TableDefinition
def uuid(opts = {})
def uuid(column_name = COLUMN_NAME, **opts)
index_opts = opts.delete(:index)
index_opts = {} if index_opts.nil?

column_name = opts.delete(:column_name) || COLUMN_NAME
column_name ||= opts.delete(:column_name)

column column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
index column_name, INDEX_OPTIONS.merge(index_opts) if index_opts
column column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts)
index column_name, **INDEX_OPTIONS.merge(index_opts) if index_opts
end
end

# Module adds method to alter table migration
module Migration
def add_uuid_column(table_name, opts = {})
def add_uuid_column(table_name, column_name = COLUMN_NAME, **opts)
index_opts = opts.delete(:index)
index_opts = {} if index_opts == true

column_name = opts.delete(:column_name) || COLUMN_NAME
column_name ||= opts.delete(:column_name)

add_column table_name, column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
add_column table_name, column_name, COLUMN_TYPE, **COLUMN_OPTIONS.merge(opts)

add_uuid_index(table_name, index_opts.merge(column_name: column_name)) if index_opts
end

def add_uuid_index(table_name, opts = {})
column_name = opts.delete(:column_name) || COLUMN_NAME

add_index table_name, column_name, INDEX_OPTIONS.merge(opts)
add_index table_name, column_name, **INDEX_OPTIONS.merge(opts)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/uuidable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Uuidable
VERSION = '0.2.9'.freeze
VERSION = '0.2.10'.freeze
end