Skip to content
代码片段 群组 项目
提交 8d76efff 编辑于 作者: Thong Kuah's avatar Thong Kuah
浏览文件

Show files affected, or modified

上级 cb9684c5
No related branches found
No related tags found
无相关合并请求
...@@ -40,6 +40,8 @@ unless system("git diff --quiet") ...@@ -40,6 +40,8 @@ unless system("git diff --quiet")
raise "There are uncommitted changes. Commit to continue." raise "There are uncommitted changes. Commit to continue."
end end
$files_affected = []
puts "Re-creating current test database" puts "Re-creating current test database"
ActiveRecord::Tasks::DatabaseTasks.drop_current ActiveRecord::Tasks::DatabaseTasks.drop_current
ActiveRecord::Tasks::DatabaseTasks.create_current ActiveRecord::Tasks::DatabaseTasks.create_current
...@@ -72,6 +74,18 @@ def exec_cmd(*args, fail: nil) ...@@ -72,6 +74,18 @@ def exec_cmd(*args, fail: nil)
false false
end end
def write_file(file_path, content)
$files_affected << file_path
File.write(file_path, content)
end
def print_files_affected
puts "The following files have been generated/modified:"
$files_affected.each do |filepath|
puts filepath
end
end
def has_lfk?(definition) def has_lfk?(definition)
Gitlab::Database::LooseForeignKeys.definitions.any? do |lfk_definition| Gitlab::Database::LooseForeignKeys.definitions.any? do |lfk_definition|
lfk_definition.from_table == definition.from_table && lfk_definition.from_table == definition.from_table &&
...@@ -133,7 +147,7 @@ def add_definition_to_yaml(definition) ...@@ -133,7 +147,7 @@ def add_definition_to_yaml(definition)
end end
# emulate existing formatting # emulate existing formatting
File.write( write_file(
Rails.root.join('config/gitlab_loose_foreign_keys.yml'), Rails.root.join('config/gitlab_loose_foreign_keys.yml'),
content.to_yaml.gsub(/^([- ] )/, ' \1') content.to_yaml.gsub(/^([- ] )/, ' \1')
) )
...@@ -169,7 +183,7 @@ def generate_migration(definition) ...@@ -169,7 +183,7 @@ def generate_migration(definition)
end end
EOF EOF
File.write(migration_name, content) write_file(migration_name, content)
exec_cmd("bin/rails", "db:migrate", fail: "Failed to run db:migrate.") exec_cmd("bin/rails", "db:migrate", fail: "Failed to run db:migrate.")
end end
...@@ -213,7 +227,7 @@ def add_test_to_specs(definition) ...@@ -213,7 +227,7 @@ def add_test_to_specs(definition)
lines = File.readlines(spec_path) lines = File.readlines(spec_path)
insert_line = lines.count - 1 insert_line = lines.count - 1
lines.insert(insert_line, "\n", *spec_test.lines) lines.insert(insert_line, "\n", *spec_test.lines)
File.write(spec_path, lines.join("")) write_file(spec_path, lines.join(""))
end end
def update_no_cross_db_foreign_keys_spec(definition) def update_no_cross_db_foreign_keys_spec(definition)
...@@ -229,7 +243,7 @@ def update_no_cross_db_foreign_keys_spec(definition) ...@@ -229,7 +243,7 @@ def update_no_cross_db_foreign_keys_spec(definition)
return return
end end
File.write(spec_path, updated.join("")) write_file(spec_path, updated.join(""))
end end
all_foreign_keys = ActiveRecord::Base.connection.tables.flat_map do |table| all_foreign_keys = ActiveRecord::Base.connection.tables.flat_map do |table|
...@@ -287,4 +301,7 @@ all_foreign_keys.each_with_index do |definition, idx| ...@@ -287,4 +301,7 @@ all_foreign_keys.each_with_index do |definition, idx|
add_test_to_specs(definition) add_test_to_specs(definition)
update_no_cross_db_foreign_keys_spec(definition) update_no_cross_db_foreign_keys_spec(definition)
end end
print_files_affected
puts puts
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册