Module: AR::UUID::Schema

Defined in:
lib/ar/uuid/schema.rb

Instance Method Summary collapse

Instance Method Details

#add_reference(table_name, ref_name, **options) ⇒ Object



25
26
27
28
29
# File 'lib/ar/uuid/schema.rb', line 25

def add_reference(table_name, ref_name, **options)
  options[:type] ||= "text"

  super
end

#create_table(table_name, **options, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ar/uuid/schema.rb', line 6

def create_table(table_name, **options, &block)
  override_id = !options.key?(:id)
  options[:id] = false if override_id
  prefix = options.delete(:prefix) || table_name
  default_function = proc do
    AR::UUID.default_function_with_prefix(prefix)
  end

  super(table_name, **options) do |t|
    if override_id
      t.primary_key :id,
                    :text,
                    default: default_function
    end

    instance_exec(t, &block)
  end
end