Commit 9af97ee6 authored by Andreas Brandl's avatar Andreas Brandl

Remove assumption about public schema

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/228724
parent 9c4ea521
-- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables -- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables
-- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872 -- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872
SET search_path=public;
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,8 +8,7 @@ module Gitlab ...@@ -8,8 +8,7 @@ module Gitlab
def dump def dump
File.open(self.class.custom_dump_filepath, 'wb') do |io| File.open(self.class.custom_dump_filepath, 'wb') do |io|
io << "-- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables\n" io << "-- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables\n"
io << "-- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872\n" io << "-- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872\n\n"
io << "SET search_path=public;\n\n"
dump_partitioned_foreign_keys(io) if partitioned_foreign_keys_exist? dump_partitioned_foreign_keys(io) if partitioned_foreign_keys_exist?
end end
......
...@@ -18,11 +18,18 @@ module Gitlab ...@@ -18,11 +18,18 @@ module Gitlab
structure.gsub!(/^SELECT pg_catalog\.set_config\('search_path'.+/, '') structure.gsub!(/^SELECT pg_catalog\.set_config\('search_path'.+/, '')
structure.gsub!(/^--.*/, "\n") structure.gsub!(/^--.*/, "\n")
structure = "SET search_path=public;\n" + structure # We typically don't assume we're working with the public schema.
# pg_dump uses fully qualified object names though, since we have multiple schemas
# in the database.
#
# The intention here is to not introduce an assumption about the standard schema,
# unless we have a good reason to do so.
structure.gsub!(/public\.(\w+)/, '\1')
structure.gsub!(/CREATE EXTENSION IF NOT EXISTS (\w+) WITH SCHEMA public;/, 'CREATE EXTENSION IF NOT EXISTS \1;')
structure.gsub!(/\n{3,}/, "\n\n") structure.gsub!(/\n{3,}/, "\n\n")
io << structure io << structure.strip
io << <<~MSG io << <<~MSG
-- schema_migrations.version information is no longer stored in this file, -- schema_migrations.version information is no longer stored in this file,
-- but instead tracked in the db/schema_migrations directory -- but instead tracked in the db/schema_migrations directory
......
SET search_path=public; CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public; CREATE TABLE abuse_reports (
CREATE TABLE public.abuse_reports (
id integer NOT NULL, id integer NOT NULL,
reporter_id integer, reporter_id integer,
user_id integer, user_id integer,
...@@ -13,20 +11,18 @@ CREATE TABLE public.abuse_reports ( ...@@ -13,20 +11,18 @@ CREATE TABLE public.abuse_reports (
cached_markdown_version integer cached_markdown_version integer
); );
CREATE SEQUENCE public.abuse_reports_id_seq CREATE SEQUENCE abuse_reports_id_seq
START WITH 1 START WITH 1
INCREMENT BY 1 INCREMENT BY 1
NO MINVALUE NO MINVALUE
NO MAXVALUE NO MAXVALUE
CACHE 1; CACHE 1;
ALTER TABLE ONLY public.abuse_reports ALTER COLUMN id SET DEFAULT nextval('public.abuse_reports_id_seq'::regclass); ALTER TABLE ONLY abuse_reports ALTER COLUMN id SET DEFAULT nextval('abuse_reports_id_seq'::regclass);
ALTER TABLE ONLY public.abuse_reports ALTER TABLE ONLY abuse_reports
ADD CONSTRAINT abuse_reports_pkey PRIMARY KEY (id); ADD CONSTRAINT abuse_reports_pkey PRIMARY KEY (id);
CREATE INDEX index_abuse_reports_on_user_id ON public.abuse_reports USING btree (user_id); CREATE INDEX index_abuse_reports_on_user_id ON abuse_reports USING btree (user_id);-- schema_migrations.version information is no longer stored in this file,
-- schema_migrations.version information is no longer stored in this file,
-- but instead tracked in the db/schema_migrations directory -- but instead tracked in the db/schema_migrations directory
-- see https://gitlab.com/gitlab-org/gitlab/-/issues/218590 for details -- see https://gitlab.com/gitlab-org/gitlab/-/issues/218590 for details
...@@ -9,7 +9,6 @@ RSpec.describe Gitlab::Database::CustomStructure do ...@@ -9,7 +9,6 @@ RSpec.describe Gitlab::Database::CustomStructure do
<<~DATA <<~DATA
-- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables -- this file tracks custom GitLab data, such as foreign keys referencing partitioned tables
-- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872 -- more details can be found in the issue: https://gitlab.com/gitlab-org/gitlab/-/issues/201872
SET search_path=public;
DATA DATA
end end
......
...@@ -15,8 +15,8 @@ RSpec.describe Gitlab::Database::SchemaCleaner do ...@@ -15,8 +15,8 @@ RSpec.describe Gitlab::Database::SchemaCleaner do
expect(subject).not_to include('COMMENT ON EXTENSION') expect(subject).not_to include('COMMENT ON EXTENSION')
end end
it 'sets the search_path' do it 'no assumption about public being the default schema' do
expect(subject.split("\n").first).to eq('SET search_path=public;') expect(subject).not_to match(/public\.\w+/)
end end
it 'cleans up the full schema as expected (blackbox test with example)' do it 'cleans up the full schema as expected (blackbox test with example)' do
......
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