Fix attempting to drop views in PostgreSQL
What does this MR do?
This MR fixes rake tasks attempting to drop views in PostgreSQL.
A customer has the pg_stat_statements
extension enabled, which creates a pg_stat_statements
view in the database. When running gitlab-rake gitlab:backup:restore BACKUP=1553890872_2019_03_29_11.8.0-ee
they get the following:
$ gitlab-rake gitlab:backup:restore BACKUP=1553890872_2019_03_29_11.8.0-ee
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2019-03-29 20:29:56 +0000 -- Cleaning the database ...
rake aborted!
ActiveRecord::StatementInvalid: PG::WrongObjectType: ERROR: "pg_stat_statements" is not a table
HINT: Use DROP VIEW to remove a view.
: DROP TABLE IF EXISTS "pg_stat_statements" CASCADE
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:42:in `block (4 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:42:in `each'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:42:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:51:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
To fix this I replaced connection.data_sources
with connection.tables
, but only for PostgreSQLAdapter as I believe #tables
is deprecated for the MySQLAdapter (ref: https://github.com/rails/rails/blob/v5.0.7.1/activerecord/CHANGELOG.md).
What are the relevant issue numbers?
Regression introduced by https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6459
Customer Zendesk ticket (internal only).
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides -
Link to e2e tests MR added if this MR has Requires e2e tests label. See the Test Planning Process. -
Security reports checked/validated by reviewer
Edited by Wei-Meng Lee