class Netfira::WebConnect::Migration
Attributes
log_to_stdout[RW]
Public Instance Methods
add_localized_string(args)
click to toggle source
# 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)
click to toggle source
# 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) { |t| ... }
click to toggle source
# 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) { |t| ... }
click to toggle source
# 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 = {}) { |t| ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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_name()
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 83 def schema_migrations_table_name Netfira::WebConnect.schema_migrations_table_name end
write(text = '')
click to toggle source
# 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
Private Instance Methods
create_sendable_table(t)
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 107 def create_sendable_table(t) t.integer :delivery_status, default: 0, limit: 3, index: true end
create_tree_table(t)
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 97 def create_tree_table(t) t.string :parent_id t.index [:shop_id, :parent_id] end
create_writable_table(t)
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 102 def create_writable_table(t) t.binary :guid, limit: 16 t.index :guid, unique: true end
l10n_suffix(name = '')
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 89 def l10n_suffix(name = '') Netfira::WebConnect.db_table_l10n_suffix name end
table_prefix(name = '')
click to toggle source
# File lib/netfira/web_connect/migration.rb, line 93 def table_prefix(name = '') Netfira::WebConnect.db_table_prefix name end