Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f236667f
Commit
f236667f
authored
Jun 28, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean db/ci_structure.sql file
Same as we do for db/structure.sql file
parent
34e1b2a7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
93 deletions
+31
-93
db/ci_structure.sql
db/ci_structure.sql
+12
-84
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+7
-4
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+12
-5
No files found.
db/ci_structure.sql
View file @
f236667f
SET
statement_timeout
=
0
;
CREATE
TABLE
ar_internal_metadata
(
SET
lock_timeout
=
0
;
SET
idle_in_transaction_session_timeout
=
0
;
SET
client_encoding
=
'UTF8'
;
SET
standard_conforming_strings
=
on
;
SELECT
pg_catalog
.
set_config
(
'search_path'
,
''
,
false
);
SET
check_function_bodies
=
false
;
SET
xmloption
=
content
;
SET
client_min_messages
=
warning
;
SET
row_security
=
off
;
SET
default_tablespace
=
''
;
SET
default_table_access_method
=
heap
;
--
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
--
CREATE
TABLE
public
.
ar_internal_metadata
(
key
character
varying
NOT
NULL
,
key
character
varying
NOT
NULL
,
value
character
varying
,
value
character
varying
,
created_at
timestamp
(
6
)
without
time
zone
NOT
NULL
,
created_at
timestamp
(
6
)
without
time
zone
NOT
NULL
,
updated_at
timestamp
(
6
)
without
time
zone
NOT
NULL
updated_at
timestamp
(
6
)
without
time
zone
NOT
NULL
);
);
CREATE
TABLE
ci_instance_variables
(
--
-- Name: ci_instance_variables; Type: TABLE; Schema: public; Owner: -
--
CREATE
TABLE
public
.
ci_instance_variables
(
id
bigint
NOT
NULL
,
id
bigint
NOT
NULL
,
variable_type
smallint
DEFAULT
1
NOT
NULL
,
variable_type
smallint
DEFAULT
1
NOT
NULL
,
masked
boolean
DEFAULT
false
,
masked
boolean
DEFAULT
false
,
...
@@ -42,78 +18,30 @@ CREATE TABLE public.ci_instance_variables (
...
@@ -42,78 +18,30 @@ CREATE TABLE public.ci_instance_variables (
CONSTRAINT
check_956afd70f1
CHECK
((
char_length
(
encrypted_value
)
<=
13579
))
CONSTRAINT
check_956afd70f1
CHECK
((
char_length
(
encrypted_value
)
<=
13579
))
);
);
CREATE
SEQUENCE
ci_instance_variables_id_seq
--
-- Name: ci_instance_variables_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE
SEQUENCE
public
.
ci_instance_variables_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
SEQUENCE
ci_instance_variables_id_seq
OWNED
BY
ci_instance_variables
.
id
;
--
CREATE
TABLE
schema_migrations
(
-- Name: ci_instance_variables_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER
SEQUENCE
public
.
ci_instance_variables_id_seq
OWNED
BY
public
.
ci_instance_variables
.
id
;
--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--
CREATE
TABLE
public
.
schema_migrations
(
version
character
varying
NOT
NULL
version
character
varying
NOT
NULL
);
);
ALTER
TABLE
ONLY
ci_instance_variables
ALTER
COLUMN
id
SET
DEFAULT
nextval
(
'ci_instance_variables_id_seq'
::
regclass
);
--
ALTER
TABLE
ONLY
ar_internal_metadata
-- Name: ci_instance_variables id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER
TABLE
ONLY
public
.
ci_instance_variables
ALTER
COLUMN
id
SET
DEFAULT
nextval
(
'public.ci_instance_variables_id_seq'
::
regclass
);
--
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER
TABLE
ONLY
public
.
ar_internal_metadata
ADD
CONSTRAINT
ar_internal_metadata_pkey
PRIMARY
KEY
(
key
);
ADD
CONSTRAINT
ar_internal_metadata_pkey
PRIMARY
KEY
(
key
);
ALTER
TABLE
ONLY
ci_instance_variables
--
-- Name: ci_instance_variables ci_instance_variables_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER
TABLE
ONLY
public
.
ci_instance_variables
ADD
CONSTRAINT
ci_instance_variables_pkey
PRIMARY
KEY
(
id
);
ADD
CONSTRAINT
ci_instance_variables_pkey
PRIMARY
KEY
(
id
);
ALTER
TABLE
ONLY
schema_migrations
--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER
TABLE
ONLY
public
.
schema_migrations
ADD
CONSTRAINT
schema_migrations_pkey
PRIMARY
KEY
(
version
);
ADD
CONSTRAINT
schema_migrations_pkey
PRIMARY
KEY
(
version
);
CREATE
UNIQUE
INDEX
index_ci_instance_variables_on_key
ON
ci_instance_variables
USING
btree
(
key
);
-- schema_migrations.version information is no longer stored in this file,
--
-- but instead tracked in the db/schema_migrations directory
-- Name: index_ci_instance_variables_on_key; Type: INDEX; Schema: public; Owner: -
-- see https://gitlab.com/gitlab-org/gitlab/-/issues/218590 for details
--
CREATE
UNIQUE
INDEX
index_ci_instance_variables_on_key
ON
public
.
ci_instance_variables
USING
btree
(
key
);
--
-- PostgreSQL database dump complete
--
SET
search_path
TO
"$user"
,
public
;
lib/tasks/gitlab/db.rake
View file @
f236667f
...
@@ -90,12 +90,15 @@ namespace :gitlab do
...
@@ -90,12 +90,15 @@ namespace :gitlab do
desc
'This adjusts and cleans db/structure.sql - it runs after db:structure:dump'
desc
'This adjusts and cleans db/structure.sql - it runs after db:structure:dump'
task
:clean_structure_sql
do
|
task_name
|
task
:clean_structure_sql
do
|
task_name
|
structure_file
=
'db/structure.sql'
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
ActiveRecord
::
Tasks
::
DatabaseTasks
.
env
).
each
do
|
db_config
|
structure_file
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
dump_filename
(
db_config
.
name
)
schema
=
File
.
read
(
structure_file
)
schema
=
File
.
read
(
structure_file
)
File
.
open
(
structure_file
,
'wb+'
)
do
|
io
|
File
.
open
(
structure_file
,
'wb+'
)
do
|
io
|
Gitlab
::
Database
::
SchemaCleaner
.
new
(
schema
).
clean
(
io
)
Gitlab
::
Database
::
SchemaCleaner
.
new
(
schema
).
clean
(
io
)
end
end
end
# Allow this task to be called multiple times, as happens when running db:migrate:redo
# Allow this task to be called multiple times, as happens when running db:migrate:redo
Rake
::
Task
[
task_name
].
reenable
Rake
::
Task
[
task_name
].
reenable
...
...
spec/tasks/gitlab/db_rake_spec.rb
View file @
f236667f
...
@@ -124,14 +124,19 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
...
@@ -124,14 +124,19 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
describe
'clean_structure_sql'
do
describe
'clean_structure_sql'
do
let_it_be
(
:clean_rake_task
)
{
'gitlab:db:clean_structure_sql'
}
let_it_be
(
:clean_rake_task
)
{
'gitlab:db:clean_structure_sql'
}
let_it_be
(
:test_task_name
)
{
'gitlab:db:_test_multiple_structure_cleans'
}
let_it_be
(
:test_task_name
)
{
'gitlab:db:_test_multiple_structure_cleans'
}
let_it_be
(
:structure_file
)
{
'db/structure.sql'
}
let_it_be
(
:input
)
{
'this is structure data'
}
let_it_be
(
:input
)
{
'this is structure data'
}
let
(
:output
)
{
StringIO
.
new
}
let
(
:output
)
{
StringIO
.
new
}
before
do
before
do
structure_files
=
%w[db/structure.sql db/ci_structure.sql]
allow
(
File
).
to
receive
(
:open
).
and_call_original
structure_files
.
each
do
|
structure_file
|
stub_file_read
(
structure_file
,
content:
input
)
stub_file_read
(
structure_file
,
content:
input
)
allow
(
File
).
to
receive
(
:open
).
with
(
structure_file
,
any_args
).
and_yield
(
output
)
allow
(
File
).
to
receive
(
:open
).
with
(
Rails
.
root
.
join
(
structure_file
).
to_s
,
any_args
).
and_yield
(
output
)
end
end
end
after
do
after
do
...
@@ -139,8 +144,10 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
...
@@ -139,8 +144,10 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
end
end
it
'can be executed multiple times within another rake task'
do
it
'can be executed multiple times within another rake task'
do
expect_multiple_executions_of_task
(
test_task_name
,
clean_rake_task
)
do
expect_multiple_executions_of_task
(
test_task_name
,
clean_rake_task
,
count:
2
)
do
expect_next_instance_of
(
Gitlab
::
Database
::
SchemaCleaner
)
do
|
cleaner
|
database_count
=
ActiveRecord
::
Base
.
configurations
.
configs_for
(
env_name:
Rails
.
env
).
size
expect_next_instances_of
(
Gitlab
::
Database
::
SchemaCleaner
,
database_count
)
do
|
cleaner
|
expect
(
cleaner
).
to
receive
(
:clean
).
with
(
output
)
expect
(
cleaner
).
to
receive
(
:clean
).
with
(
output
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment