diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2018-07-09 23:31:45 +0200 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2018-08-10 20:40:00 +0200 |
commit | 119c49172f6ff37605d72faf2e4868ecdb696a61 (patch) | |
tree | f80513221cc660d6dd67d6edaffdbdcf469fe4ee /db/migrate/20180113220114_rework_redirect_routes_indexes.rb | |
parent | 09e7c75d1bf871d0c011ea0f9abfb56fab03b919 (diff) | |
download | gitlab-ce-119c49172f6ff37605d72faf2e4868ecdb696a61.tar.gz |
Fix specs to use `disable_statement_timeout` correctly
Diffstat (limited to 'db/migrate/20180113220114_rework_redirect_routes_indexes.rb')
-rw-r--r-- | db/migrate/20180113220114_rework_redirect_routes_indexes.rb | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/db/migrate/20180113220114_rework_redirect_routes_indexes.rb b/db/migrate/20180113220114_rework_redirect_routes_indexes.rb index ab9971be074..7748104f436 100644 --- a/db/migrate/20180113220114_rework_redirect_routes_indexes.rb +++ b/db/migrate/20180113220114_rework_redirect_routes_indexes.rb @@ -18,51 +18,51 @@ class ReworkRedirectRoutesIndexes < ActiveRecord::Migration OLD_INDEX_NAME_PATH_LOWER = "index_on_redirect_routes_lower_path" def up - disable_statement_timeout - - # this is a plain btree on a single boolean column. It'll never be - # selective enough to be valuable. This class is called by - # setup_postgresql.rake so it needs to be able to handle this - # index not existing. - if index_exists?(:redirect_routes, :permanent) - remove_concurrent_index(:redirect_routes, :permanent) - end + disable_statement_timeout(transaction: false) do + # this is a plain btree on a single boolean column. It'll never be + # selective enough to be valuable. This class is called by + # setup_postgresql.rake so it needs to be able to handle this + # index not existing. + if index_exists?(:redirect_routes, :permanent) + remove_concurrent_index(:redirect_routes, :permanent) + end - # If we're on MySQL then the existing index on path is ok. But on - # Postgres we need to clean things up: - return unless Gitlab::Database.postgresql? + # If we're on MySQL then the existing index on path is ok. But on + # Postgres we need to clean things up: + return unless Gitlab::Database.postgresql? - if_not_exists = Gitlab::Database.version.to_f >= 9.5 ? "IF NOT EXISTS" : "" + if_not_exists = Gitlab::Database.version.to_f >= 9.5 ? "IF NOT EXISTS" : "" - # Unique index on lower(path) across both types of redirect_routes: - execute("CREATE UNIQUE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_UNIQUE} ON redirect_routes (lower(path) varchar_pattern_ops);") + # Unique index on lower(path) across both types of redirect_routes: + execute("CREATE UNIQUE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_UNIQUE} ON redirect_routes (lower(path) varchar_pattern_ops);") - # Make two indexes on path -- one for permanent and one for temporary routes: - execute("CREATE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);") - execute("CREATE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;") + # Make two indexes on path -- one for permanent and one for temporary routes: + execute("CREATE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);") + execute("CREATE INDEX CONCURRENTLY #{if_not_exists} #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;") - # Remove the old indexes: + # Remove the old indexes: - # This one needed to be on lower(path) but wasn't so it's replaced with the two above - execute "DROP INDEX CONCURRENTLY IF EXISTS #{OLD_INDEX_NAME_PATH_TPOPS};" + # This one needed to be on lower(path) but wasn't so it's replaced with the two above + execute "DROP INDEX CONCURRENTLY IF EXISTS #{OLD_INDEX_NAME_PATH_TPOPS};" - # This one isn't needed because we only ever do = and LIKE on this - # column so the varchar_pattern_ops index is sufficient - execute "DROP INDEX CONCURRENTLY IF EXISTS #{OLD_INDEX_NAME_PATH_LOWER};" + # This one isn't needed because we only ever do = and LIKE on this + # column so the varchar_pattern_ops index is sufficient + execute "DROP INDEX CONCURRENTLY IF EXISTS #{OLD_INDEX_NAME_PATH_LOWER};" + end end def down - disable_statement_timeout + disable_statement_timeout(transaction: false) do + add_concurrent_index(:redirect_routes, :permanent) - add_concurrent_index(:redirect_routes, :permanent) + return unless Gitlab::Database.postgresql? - return unless Gitlab::Database.postgresql? + execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_TPOPS} ON redirect_routes (path varchar_pattern_ops);") + execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_LOWER} ON redirect_routes (LOWER(path));") - execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_TPOPS} ON redirect_routes (path varchar_pattern_ops);") - execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_LOWER} ON redirect_routes (LOWER(path));") - - execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_UNIQUE};") - execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};") - execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};") + execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_UNIQUE};") + execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};") + execute("DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};") + end end end |