Method: Netfira::WebConnect::Migration#create_record_table

Defined in:
lib/netfira/web_connect/migration.rb

#create_record_table(table_name, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/netfira/web_connect/migration.rb', line 18

def create_record_table(table_name, options = {})
  Refinements.running_migration = self
  @l10n_buffer = options[:with_l10n] && []
  options[:writable] ||= options[:sendable]
  create_table table_name, options do |t|
    t.string options[:origin_key] || :"#{table_name.to_s.singularize}_id", index: true unless options[:writable]
    yield t
    t.references :shop, index: true
    create_tree_table t if options[:tree]
    create_writable_table t if options[:writable]
    create_sendable_table t if options[:sendable]
    t.binary :digest, limit: 16
    t.timestamps
    t.datetime :deleted_at
    t.index :deleted_at
  end
  if @l10n_buffer
    create_l10n_table table_name do |t|
      @l10n_buffer.each do |args|
        t.string *args
      end
    end
  end
  add_table_def table_name, options
end