Commit 419d61da authored by pbair's avatar pbair

Reenable gitlab:db:clean_structure_sql task

After execution of the rask task, reenable so that subsequent
invocations will execute. This fixes an issue where db:migrate:redo was
not properly stripping comments from structure.sql
parent 4d2d7099
...@@ -80,13 +80,16 @@ namespace :gitlab do ...@@ -80,13 +80,16 @@ namespace :gitlab do
end end
desc 'This adjusts and cleans db/structure.sql - it runs after db:structure:dump' desc 'This adjusts and cleans db/structure.sql - it runs after db:structure:dump'
task :clean_structure_sql do task :clean_structure_sql do |task_name|
structure_file = 'db/structure.sql' structure_file = 'db/structure.sql'
schema = File.read(structure_file) schema = File.read(structure_file)
File.open(structure_file, 'wb+') do |io| File.open(structure_file, 'wb+') do |io|
Gitlab::Database::SchemaCleaner.new(schema).clean(io) Gitlab::Database::SchemaCleaner.new(schema).clean(io)
end end
# Allow this task to be called multiple times, as happens when running db:migrate:redo
Rake::Task[task_name].reenable
end end
# Inform Rake that gitlab:schema:fix_structure_sql should be run every time rake db:structure:dump is run # Inform Rake that gitlab:schema:fix_structure_sql should be run every time rake db:structure:dump is run
......
...@@ -98,8 +98,28 @@ describe 'gitlab:db namespace rake task' do ...@@ -98,8 +98,28 @@ describe 'gitlab:db namespace rake task' do
end end
end end
describe 'clean_structure_sql' do
let_it_be(:clean_rake_task) { 'gitlab:db:clean_structure_sql' }
let_it_be(:structure_file) { 'db/structure.sql' }
let_it_be(:input) { 'this is structure data' }
let(:output) { StringIO.new }
it 'reenables the task after running' do
allow(File).to receive(:read).with(structure_file).and_return(input)
allow(File).to receive(:open).with(structure_file, any_args).and_yield(output)
expect_any_instance_of(Gitlab::Database::SchemaCleaner).to receive(:clean).with(output)
run_rake_task(clean_rake_task) do |rake_task|
expect(rake_task).to receive(:reenable)
end
end
end
def run_rake_task(task_name) def run_rake_task(task_name)
Rake::Task[task_name].reenable rake_task = Rake::Task[task_name]
rake_task.reenable
yield rake_task if block_given?
Rake.application.invoke_task task_name Rake.application.invoke_task task_name
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment