Class: Netfira::WebConnect::Migration

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/netfira/web_connect/migration.rb,
lib/netfira/web_connect/migration/refinements.rb

Direct Known Subclasses

Alpha, Support

Defined Under Namespace

Modules: Refinements

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.log_to_stdoutObject

Returns the value of attribute log_to_stdout.



7
8
9
# File 'lib/netfira/web_connect/migration.rb', line 7

def log_to_stdout
  @log_to_stdout
end

Instance Method Details

#add_localized_string(args) ⇒ Object



10
11
12
# File 'lib/netfira/web_connect/migration.rb', line 10

def add_localized_string(args)
  @l10n_buffer << args if @l10n_buffer
end

#add_table_def(table_name, options) ⇒ Object



72
73
74
# File 'lib/netfira/web_connect/migration.rb', line 72

def add_table_def(table_name, options)
  Models::Table.create options.select{|k| %i[origin_key writable sendable file].include? k}.merge name: table_name
end

#create_file_table(table_name) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/netfira/web_connect/migration.rb', line 52

def create_file_table(table_name)
  create_record_table table_name, origin_key: :file_name, file: true do |t|
    t.string :remote_location
    t.string :locale
    yield t if block_given?
    t.integer :size
    t.binary :checksum, limit: 16
  end
end

#create_l10n_table(table_name) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/netfira/web_connect/migration.rb', line 44

def create_l10n_table(table_name)
  create_table l10n_suffix(table_name) do |t|
    t.references table_name.to_s.singularize.to_sym, index: true
    t.string :language, limit: 20, index: true
    yield t
  end
end

#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

#create_relation_table(first, second) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/netfira/web_connect/migration.rb', line 62

def create_relation_table(first, second)
  first, second = [first, second].sort
  create_table :"#{first}_to_#{second}" do |t|
    t.references first.to_s.singularize, second.to_s.singularize, index: true
    t.timestamps
    t.datetime :deleted_at
    t.index :deleted_at
  end
end

#create_table(table_name, options = {}, &block) ⇒ Object



14
15
16
# File 'lib/netfira/web_connect/migration.rb', line 14

def create_table(table_name, options = {}, &block)
  super table_prefix(table_name), options, &block
end

#schema_migrations_table_nameObject



83
84
85
# File 'lib/netfira/web_connect/migration.rb', line 83

def schema_migrations_table_name
  Netfira::WebConnect.schema_migrations_table_name
end

#write(text = '') ⇒ Object



76
77
78
79
80
81
# File 'lib/netfira/web_connect/migration.rb', line 76

def write(text = '')
  if verbose
    puts text if Migration.log_to_stdout
    Netfira::WebConnect.logger.info text
  end
end