Fix syntax (w/Rubocop) in db migrations, seeds

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/3194/head
Alex Coles 9 years ago
parent 35ef50b868
commit 36d0f638ba
  1. 4
      db/migrate/000_aggregated_migrations.rb
  2. 1
      db/migrate/20120809131659_create_wiki_menu_item_for_existing_wikis.rb
  3. 1
      db/migrate/20130409133705_create_timelines_alternate_dates.rb
  4. 2
      db/migrate/20130724143418_add_planning_element_type_properties_to_type.rb
  5. 1
      db/migrate/20130916123916_planning_element_types_data_to_types.rb
  6. 5
      db/migrate/20130917131710_planning_element_data_to_work_packages.rb
  7. 2
      db/migrate/20130918111753_migrate_user_rights.rb
  8. 2
      db/migrate/20130920081120_journal_indices.rb
  9. 1
      db/migrate/20130920081135_legacy_attachment_journal_data.rb
  10. 2
      db/migrate/20130920093823_legacy_wiki_content_journal_data.rb
  11. 5
      db/migrate/20131024140048_migrate_timelines_options.rb
  12. 4
      db/migrate/migration_utils/attachable_utils.rb
  13. 4
      db/migrate/migration_utils/customizable_utils.rb
  14. 4
      db/migrate/migration_utils/journal_migrator_concerns.rb
  15. 9
      db/migrate/migration_utils/legacy_journal_migrator.rb
  16. 21
      db/migrate/migration_utils/text_references.rb
  17. 2
      db/migrate/migration_utils/yaml_migrator.rb
  18. 5
      db/seeds/development.rb
  19. 2
      db/seeds/production.rb

@ -858,9 +858,9 @@ class AggregatedMigrations < ActiveRecord::Migration
end
def aggregated_versions
@@aggregated_versions ||= @@migrations.split.map do |m|
@@aggregated_versions ||= @@migrations.split.map { |m|
m.gsub(/_.*\z/, '').to_i
end
}
end
def all_versions

@ -30,7 +30,6 @@
class CreateWikiMenuItemForExistingWikis < ActiveRecord::Migration
def self.up
Wiki.all.each do |wiki|
page = wiki.find_page(wiki.start_page, with_redirects: true)
current_title = page.present? ?

@ -37,7 +37,6 @@ class CreateTimelinesAlternateDates < ActiveRecord::Migration
t.belongs_to :planning_element
t.timestamps
end
add_index :timelines_alternate_dates, :planning_element_id
add_index :timelines_alternate_dates, :scenario_id

@ -44,7 +44,7 @@ class AddPlanningElementTypePropertiesToType < ActiveRecord::Migration
add_column :types, :updated_at, :datetime
::Type.update_all({ created_at: Time.now, updated_at: Time.now },
{ created_at: nil, updated_at: nil })
created_at: nil, updated_at: nil)
change_column :types, :created_at, :datetime, null: false
change_column :types, :updated_at, :datetime, null: false

@ -171,7 +171,6 @@ class PlanningElementTypesDataToTypes < ActiveRecord::Migration
return if all_workflow_states.empty?
all_workflow_states.in_groups_of(100, false) do |some_workflow_states|
some_workflow_states = some_workflow_states.join(', ')
execute <<-SQL

@ -74,7 +74,6 @@ class PlanningElementDataToWorkPackages < ActiveRecord::Migration
default_priority_id = get_default_priority_id
with_temporary_legacy_id_column do
insert_legacy_planning_elements_entries_to_work_packages(default_status_id, default_priority_id)
update_legacy_planning_elements_with_new_id
@ -325,13 +324,13 @@ class PlanningElementDataToWorkPackages < ActiveRecord::Migration
end
def skip_on_no_planning_elements
planning_element = suppress_messages do
planning_element = suppress_messages {
select_one <<-SQL
SELECT #{db_column('id')}
FROM #{db_planning_elements_table}
LIMIT 1
SQL
end
}
if planning_element.present?
false

@ -94,7 +94,7 @@ class MigrateUserRights < ActiveRecord::Migration
unless row[COLUMN].nil?
role_permissions = YAML.load row[COLUMN]
role_permissions.map! { |p| permissions.has_key?(p) ? permissions[p] : p }
role_permissions.map! do |p| permissions.has_key?(p) ? permissions[p] : p end
row[COLUMN] = YAML.dump role_permissions.flatten
end

@ -33,7 +33,7 @@ class JournalIndices < ActiveRecord::Migration
# the real(tm) journals-table
if ActiveRecord::Base.connection.table_exists? :legacy_journals
ActiveRecord::Base.connection.indexes(:legacy_journals).map(&:name).each { |index_name| remove_index :legacy_journals, name: index_name }
ActiveRecord::Base.connection.indexes(:legacy_journals).map(&:name).each do |index_name| remove_index :legacy_journals, name: index_name end
add_index :legacy_journals, :activity_type, name: 'idx_lgcy_journals_on_activity_type'
add_index :legacy_journals, :created_at, name: 'idx_lgcy_journals_on_created_at'

@ -46,7 +46,6 @@ class LegacyAttachmentJournalData < ActiveRecord::Migration
def migrator
@migrator ||= Migration::LegacyJournalMigrator.new('AttachmentJournal', 'attachment_journals') do
def migrate_key_value_pairs!(to_insert, _legacy_journal, _journal_id)
rewrite_issue_container_to_work_package(to_insert)
end

@ -47,7 +47,6 @@ class LegacyWikiContentJournalData < ActiveRecord::Migration
def migrator
@migrator ||= Migration::LegacyJournalMigrator.new('WikiContentJournal', 'wiki_content_journals') do
def migrate_key_value_pairs!(to_insert, legacy_journal, journal_id)
# remove once lock_version is no longer a column in the wiki_content_journales table
if !to_insert.has_key?('lock_version')
@ -86,7 +85,6 @@ class LegacyWikiContentJournalData < ActiveRecord::Migration
end
end
end
end
end

@ -128,8 +128,7 @@ class MigrateTimelinesOptions < ActiveRecord::Migration
calling_class.contains_none_element = calling_class.contains_none_element? || pe_types.empty?
pe_types = pe_types.empty? ? new_ids_of_former_pes
: pe_types.map { |p| pe_type_id_map[p.to_i].to_s }
pe_types = pe_types.empty? ? new_ids_of_former_pes : pe_types.map { |p| pe_type_id_map[p.to_i].to_s }
timelines_opts[PE_TYPE_KEY] = pe_types
@ -141,7 +140,7 @@ class MigrateTimelinesOptions < ActiveRecord::Migration
pe_time_types = timelines_opts[PE_TIME_TYPE_KEY]
pe_time_types.map! { |p| pe_type_id_map[p.to_i].to_s }
pe_time_types.map! do |p| pe_type_id_map[p.to_i].to_s end
timelines_opts[PE_TIME_TYPE_KEY] = pe_time_types

@ -46,7 +46,7 @@ module Migration::Utils
def repair_attachable_journal_entries(journal_type, legacy_journal_type)
result = invalid_attachments(legacy_journal_type)
result.map { |m| m.journaled_type = journal_type }
result.map do |m| m.journaled_type = journal_type end
repair_journals(result)
end
@ -54,7 +54,7 @@ module Migration::Utils
def remove_initial_journal_entries(journal_type, legacy_journal_type)
result = invalid_attachments(legacy_journal_type)
result.map { |m| m.journaled_type = journal_type }
result.map do |m| m.journaled_type = journal_type end
remove_initial_journals(result)
end

@ -48,7 +48,7 @@ module Migration::Utils
def repair_customizable_journal_entries(journal_type, legacy_journal_type)
result = invalid_custom_values(legacy_journal_type)
result.map { |m| m.journaled_type = journal_type }
result.map do |m| m.journaled_type = journal_type end
repair_journals(result)
end
@ -56,7 +56,7 @@ module Migration::Utils
def remove_customizable_journal_entries(journal_type, legacy_journal_type)
result = invalid_custom_values(legacy_journal_type)
result.map { |m| m.journaled_type = journal_type }
result.map do |m| m.journaled_type = journal_type end
remove_initial_journals(result)
end

@ -80,12 +80,12 @@ module Migration
# sometimes there are attachments, which were deleted in a later journal entry
# there is not need to add those attachments, so we filter them out here
def remove_attachments_deleted_in_current_version(attachments, journal_to_insert)
deleted_attachments = attachments.select do |key|
deleted_attachments = attachments.select { |key|
# journal_to_insert[key] is of the form
# [nil, "filename.ext"] when the attachment was added
# ["filename.ext", nil] when the attachment was removed
journal_to_insert[key].first
end
}
attachments.reject do |key|
deleted_attachments.any? { |del_key| key =~ /attachments#{del_key[attachment_key_regexp, 1]}/ }
end

@ -94,7 +94,6 @@ module Migration
if legacy_table_exists?
table_names.each do |table_name|
db_delete <<-SQL
DELETE
FROM #{quoted_table_name(table_name)}
@ -102,7 +101,6 @@ module Migration
FROM #{quoted_legacy_journals_table_name}
WHERE type=#{quote_value(type)})
SQL
end
db_delete <<-SQL
@ -179,7 +177,8 @@ module Migration
# fetches specific journal row. might be empty.
def fetch_journal(legacy_journal)
id, version = legacy_journal['journaled_id'], legacy_journal['version']
id = legacy_journal['journaled_id']
version = legacy_journal['version']
db_select_all <<-SQL
SELECT *
@ -256,7 +255,7 @@ module Migration
values = to_insert.values
db_execute <<-SQL
INSERT INTO #{journal_table_name} (journal_id#{', ' + keys.join(', ') unless keys.empty? })
INSERT INTO #{journal_table_name} (journal_id#{', ' + keys.join(', ') unless keys.empty?})
VALUES (#{quote_value(journal_id)}#{', ' + values.map { |d| quote_value(d) }.join(', ') unless values.empty?});
SQL
@ -266,7 +265,7 @@ module Migration
def update_data_journal(id, to_insert)
db_execute <<-SQL unless to_insert.empty?
UPDATE #{journal_table_name}
SET #{(to_insert.each.map { |key, value| "#{key} = #{quote_value(value)}" }).join(', ') }
SET #{(to_insert.each.map { |key, value| "#{key} = #{quote_value(value)}" }).join(', ')}
WHERE id = #{id};
SQL
end

@ -119,7 +119,7 @@ module Migration
def update_work_package_macros(text, id_map, regex, macro_regex, new_macro)
unless text.nil?
text = parse_non_pre_blocks(text) do |block|
text = parse_non_pre_blocks(text) { |block|
block.gsub!(regex) do |match|
if id_map.has_key? $~[:id].to_s
prefix = $~.names.include?('prefix') ? $~[:prefix] : ' '
@ -132,7 +132,7 @@ module Migration
match
end
end
end
}
end
text
@ -140,10 +140,10 @@ module Migration
def update_issue_planning_element_links(text, id_map)
unless text.nil?
text = parse_non_pre_blocks(text) do |block|
block.gsub!(work_package_link_regex) { |_| update_issue_planning_element_link_match $~, id_map }
text = parse_non_pre_blocks(text) { |block|
block.gsub!(work_package_link_regex) do |_| update_issue_planning_element_link_match $~, id_map end
block.gsub!(rel_work_package_link_regex) { |_| update_issue_planning_element_link_match $~, id_map }
end
}
end
text
@ -159,10 +159,10 @@ module Migration
def restore_issue_planning_element_links(text, id_map)
unless text.nil?
text = parse_non_pre_blocks(text) do |_block|
text.gsub!(restore_work_package_link_regex) { |_| restore_issue_planning_element_link_match $~, id_map }
text = parse_non_pre_blocks(text) { |_block|
text.gsub!(restore_work_package_link_regex) do |_| restore_issue_planning_element_link_match $~, id_map end
text.gsub!(restore_rel_work_package_link_regex) { |_| restore_issue_planning_element_link_match $~, id_map }
end
}
end
text
@ -206,7 +206,10 @@ module Migration
parsed = ''
while !s.eos?
s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
text = s[1]
full_tag = s[2]
closing = s[3]
tag = s[4]
if tags.empty?
yield text
end

@ -36,7 +36,7 @@ module Migration
def migrate_yaml(table, column, source_yamler, target_yamler)
current_yamler = YAML::ENGINE.yamler
fetch_data(table, column).each do | data |
fetch_data(table, column).each do |data|
db_execute <<-SQL
UPDATE #{quoted_table_name(table)}
SET #{db_column(column)} = #{quote_value(yaml_to_yaml(data[column], source_yamler, target_yamler))}

@ -165,10 +165,9 @@ user_count.times do |count|
description: Faker::Lorem.paragraph(5, true, 3),
start_date: s = Date.today - (25 - rand(50)).days,
due_date: s + (1 + rand(120)).days
)
)
work_package.type = types.sample
work_package.save!
end
## extend user's last issue
@ -231,7 +230,6 @@ user_count.times do |count|
## add attachments
3.times do |_attachment_count|
attachment = Attachment.new(container: issue,
author: user,
file: OpenProject::Files.create_uploaded_file(
@ -239,7 +237,6 @@ user_count.times do |count|
attachment.save!
issue.attachments << attachment
end
## add custom values

@ -54,5 +54,5 @@ end
# (from todays standpoint) the assignment is done covertedly.
[WorkPackage, Journal::WorkPackageJournal].each do |klass|
klass.update_all({ type_id: standard_type.id }, { type_id: [0, nil] })
klass.update_all({ type_id: standard_type.id }, type_id: [0, nil])
end

Loading…
Cancel
Save