Drop user defined functions in `rake gitlab:db:drop_tables`
What does this MR do and why?
Previously the backup restore Rake task would fail if the schema were
loaded and then dropped via rake gitlab:db:drop_tables
because the
task would not clean up the 13 user-defined functions in the
schema. The CREATE FUNCTION
in db/structure.sql
would fail the
restore because it would collide with an existing function.
Since DROP DATABASE
may need superuser permissions, the backup
restore task expects that rake gitlab:db:drop_tables
brings the
database into a clean state. To ensure that's the case, we now search
for all user defined functions and drop them. Note that while most of
the functions are used with triggers, next_traversal_ids_sibling
is
a noteable exception.
Relates to #356032 (closed)
How to set up and validate locally
- Run
RAILS_ENV=test bundle exec rake db:reset
gdk psql -d gitlabhq_test
- See the list of functions:
\df+
- See the list of
plpgsql
functions:
SELECT p.proname FROM pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
WHERE pg_catalog.pg_function_is_visible(p.oid)
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND l.lanname = 'plpgsql';
- Run
RAILS_ENV=test bundle exec rake gitlab:db:drop_tables
. - Repeat steps 3 and 4. You should all the
plpgsql
functions wiped. - Repeat step 1 to bring your database back to normal.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.