Module: Cms::Upgrades::V3_5_0::Retroactive_v3_4_0Updates

Defined in:
lib/cms/upgrades/v3_5_0.rb

Overview

Technically these updates are for v3_4_0, but I want to avoid having to change existing migrations

These migrations are designed to make it easy for modules to write migrations for their content blocks with minimal code.

Instance Method Summary collapse

Instance Method Details

#v3_5_0_apply_namespace_to_block(module_name, model_class_name) ⇒ Object

Applys table namespacing and other fixes to blocks that need upgrading from < 3.4.0 to 3.5.

Parameters:

  • module_name (String)

    I.e. module table_prefix (i.e. BcmsWhatever)

  • model_class_name (String)

    I.e. ‘Slide’ or ‘NewsArticle’



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cms/upgrades/v3_5_0.rb', line 19

def v3_5_0_apply_namespace_to_block(module_name, model_class_name)
  puts "Applying namespace '#{module_name}' to model '#{model_class_name}'"
  table_prefix = module_name.underscore
  model_name = model_class_name.underscore

  old_content_table = model_name.pluralize
  new_content_table = "#{table_prefix}_#{model_name.pluralize}"
  rename_table old_content_table, new_content_table if have_not_renamed(old_content_table, new_content_table)


  old_versions_table = "#{model_name}_versions"
  new_versions_table = "#{table_prefix}_#{model_name}_versions"
  rename_table old_versions_table, new_versions_table if have_not_renamed(old_versions_table, new_versions_table)
  v3_5_0_standardize_version_id_column(table_prefix, model_name)
  v3_5_0_namespace_model_data(module_name, model_class_name)
  v3_5_0_update_connector_namespaces(module_name, model_class_name)
end

#v3_5_0_namespace_model(module_name, model_class_name) ⇒ Object



59
60
61
# File 'lib/cms/upgrades/v3_5_0.rb', line 59

def v3_5_0_namespace_model(module_name, model_class_name)
  "#{module_name}::#{model_class_name}"
end

#v3_5_0_namespace_model_data(module_name, model_class_name) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/cms/upgrades/v3_5_0.rb', line 43

def v3_5_0_namespace_model_data(module_name, model_class_name)
  found = Cms::ContentType.named(model_class_name).first
  if found
    found.name = v3_5_0_namespace_model(module_name, model_class_name)
    found.save!
  end
end

#v3_5_0_standardize_version_id_column(table_prefix, model_name) ⇒ Object



37
38
39
40
41
# File 'lib/cms/upgrades/v3_5_0.rb', line 37

def v3_5_0_standardize_version_id_column(table_prefix, model_name)
  if column_exists?("#{table_prefix}_#{model_name}_versions", "#{model_name}_id")
    rename_column("#{table_prefix}_#{model_name}_versions", "#{model_name}_id", :original_record_id)
  end
end

#v3_5_0_update_connector_namespaces(module_name, model_class_name) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/cms/upgrades/v3_5_0.rb', line 51

def v3_5_0_update_connector_namespaces(module_name, model_class_name)
  namespaced_class = v3_5_0_namespace_model(module_name, model_class_name)
  Cms::Connector.where(:connectable_type => model_class_name).each do |connector|
    connector.connectable_type = namespaced_class
    connector.save!
  end
end