Commit 2a291cd8 authored by Andreas Brandl's avatar Andreas Brandl

Drop all views in gitlab:db:drop_tables

The intent here is to end up with a clean database, hence we also should
drop any views.
parent 2cc94060
......@@ -35,6 +35,11 @@ namespace :gitlab do
# Truncate schema_migrations to ensure migrations re-run
connection.execute('TRUNCATE schema_migrations') if connection.table_exists? 'schema_migrations'
# Drop any views
connection.views.each do |view|
connection.execute("DROP VIEW IF EXISTS #{connection.quote_table_name(view)} CASCADE")
end
# Drop tables with cascade to avoid dependent table errors
# PG: http://www.postgresql.org/docs/current/static/ddl-depend.html
# Add `IF EXISTS` because cascade could have already deleted a table.
......
......@@ -164,7 +164,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
end
end
describe 'drop_tables', :focus do
describe 'drop_tables' do
subject { run_rake_task('gitlab:db:drop_tables') }
let(:tables) { %w(one two) }
......@@ -185,6 +185,13 @@ RSpec.describe 'gitlab:db namespace rake task' do
subject
end
it 'drops all views' do
expect(connection).to receive(:execute).with('DROP VIEW IF EXISTS "three" CASCADE')
expect(connection).to receive(:execute).with('DROP VIEW IF EXISTS "four" CASCADE')
subject
end
it 'truncates schema_migrations table' do
expect(connection).to receive(:execute).with('TRUNCATE schema_migrations')
......
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