Class: Netfira::WebConnect::Migration
- Inherits:
-
ActiveRecord::Migration
- Object
- ActiveRecord::Migration
- Netfira::WebConnect::Migration
- Defined in:
- lib/netfira/web_connect/migration.rb,
lib/netfira/web_connect/migration/refinements.rb
Defined Under Namespace
Modules: Refinements
Class Attribute Summary collapse
-
.log_to_stdout ⇒ Object
Returns the value of attribute log_to_stdout.
Instance Method Summary collapse
- #add_localized_string(args) ⇒ Object
- #add_table_def(table_name, options, is_file = false) ⇒ Object
- #create_file_table(table_name) ⇒ Object
- #create_l10n_table(table_name) ⇒ Object
- #create_record_table(table_name, options = {}) ⇒ Object
- #create_relation_table(first, second) ⇒ Object
- #create_table(table_name, options = {}, &block) ⇒ Object
- #schema_migrations_table_name ⇒ Object
- #write(text = '') ⇒ Object
Class Attribute Details
.log_to_stdout ⇒ Object
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, is_file = false) ⇒ Object
84 85 86 87 |
# File 'lib/netfira/web_connect/migration.rb', line 84 def add_table_def(table_name, , is_file = false) Models::Table.create .select{|k| i[origin_key writable sendable].include? k}.merge name: table_name, file: is_file end |
#create_file_table(table_name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/netfira/web_connect/migration.rb', line 57 def create_file_table(table_name) create_table table_name do |t| t.references :shop, index: true t.string :file_name, index: true t.string :remote_location t.string :locale yield t if block_given? t.integer :size t.binary :checksum, limit: 16 t.binary :digest, limit: 16 t. t.datetime :deleted_at t.index :deleted_at end add_table_def table_name, {}, true end |
#create_l10n_table(table_name) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/netfira/web_connect/migration.rb', line 49 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 43 44 45 46 47 |
# File 'lib/netfira/web_connect/migration.rb', line 18 def create_record_table(table_name, = {}) Refinements.running_migration = self @l10n_buffer = [:with_l10n] && [] [:writable] ||= [:sendable] create_table table_name, do |t| t.string [:origin_key] || :"#{table_name.to_s.singularize}_id", index: true unless [:writable] yield t t.references :shop, index: true if [:tree] t.string :parent_id t.index [:shop_id, :parent_id] end if [:sendable] t.binary :guid, index: true t.integer :delivery_status, default: 0, limit: 3, index: true end t.binary :digest, limit: 16 t. 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, end |
#create_relation_table(first, second) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/netfira/web_connect/migration.rb', line 74 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. 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, = {}, &block) super table_prefix(table_name), , &block end |
#schema_migrations_table_name ⇒ Object
96 97 98 |
# File 'lib/netfira/web_connect/migration.rb', line 96 def schema_migrations_table_name Netfira::WebConnect.schema_migrations_table_name end |
#write(text = '') ⇒ Object
89 90 91 92 93 94 |
# File 'lib/netfira/web_connect/migration.rb', line 89 def write(text = '') if verbose puts text if Migration.log_to_stdout Netfira::WebConnect.logger.info text end end |