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
715b921c
Commit
715b921c
authored
Oct 27, 2021
by
Dylan Griffith
Committed by
Adam Hegyi
Oct 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move gitlab_schema yml/code from spec/support to lib/gitlab
parent
ad65339f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
23 deletions
+25
-23
lib/gitlab/database/gitlab_schema.rb
lib/gitlab/database/gitlab_schema.rb
+22
-0
lib/gitlab/database/gitlab_schemas.yml
lib/gitlab/database/gitlab_schemas.yml
+0
-0
spec/lib/gitlab/database/gitlab_schema_spec.rb
spec/lib/gitlab/database/gitlab_schema_spec.rb
+1
-1
spec/support/database/gitlab_schema.rb
spec/support/database/gitlab_schema.rb
+0
-20
spec/support/database/prevent_cross_database_modification.rb
spec/support/database/prevent_cross_database_modification.rb
+1
-1
spec/support/database/prevent_cross_joins.rb
spec/support/database/prevent_cross_joins.rb
+1
-1
No files found.
lib/gitlab/database/gitlab_schema.rb
0 → 100644
View file @
715b921c
# frozen_string_literal: true
# This module gathers information about table to schema mapping
# to understand table affinity
module
Gitlab
module
Database
module
GitlabSchema
def
self
.
table_schemas
(
tables
)
tables
.
map
{
|
table
|
table_schema
(
table
)
}.
to_set
end
def
self
.
table_schema
(
name
)
# When undefined it's best to return a unique name so that we don't incorrectly assume that 2 undefined schemas belong on the same database
tables_to_schema
[
name
]
||
:"undefined_
#{
name
}
"
end
def
self
.
tables_to_schema
@tables_to_schema
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'lib/gitlab/database/gitlab_schemas.yml'
))
end
end
end
end
spec/support
/database/gitlab_schemas.yml
→
lib/gitlab
/database/gitlab_schemas.yml
View file @
715b921c
File moved
spec/
support_specs
/database/gitlab_schema_spec.rb
→
spec/
lib/gitlab
/database/gitlab_schema_spec.rb
View file @
715b921c
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Database
::
GitlabSchema
do
RSpec
.
describe
Gitlab
::
Database
::
GitlabSchema
do
it
'matches all the tables in the database'
,
:aggregate_failures
do
# These tables do not need a gitlab_schema
excluded_tables
=
%w(ar_internal_metadata schema_migrations)
...
...
spec/support/database/gitlab_schema.rb
deleted
100644 → 0
View file @
ad65339f
# frozen_string_literal: true
# This module gathes information about table to schema mapping
# to understand table affinity
module
Database
module
GitlabSchema
def
self
.
table_schemas
(
tables
)
tables
.
map
{
|
table
|
table_schema
(
table
)
}.
to_set
end
def
self
.
table_schema
(
name
)
# When undefined it's best to return a unique name so that we don't incorrectly assume that 2 undefined schemas belong on the same database
tables_to_schema
[
name
]
||
:"undefined_
#{
name
}
"
end
def
self
.
tables_to_schema
@tables_to_schema
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'spec/support/database/gitlab_schemas.yml'
))
end
end
end
spec/support/database/prevent_cross_database_modification.rb
View file @
715b921c
...
...
@@ -100,7 +100,7 @@ module Database
cross_database_context
[
:modified_tables_by_db
][
database
].
merge
(
tables
)
all_tables
=
cross_database_context
[
:modified_tables_by_db
].
values
.
map
(
&
:to_a
).
flatten
schemas
=
Database
::
GitlabSchema
.
table_schemas
(
all_tables
)
schemas
=
::
Gitlab
::
Database
::
GitlabSchema
.
table_schemas
(
all_tables
)
if
schemas
.
many?
message
=
"Cross-database data modification of '
#{
schemas
.
to_a
.
join
(
", "
)
}
' were detected within "
\
...
...
spec/support/database/prevent_cross_joins.rb
View file @
715b921c
...
...
@@ -35,7 +35,7 @@ module Database
# https://github.com/pganalyze/pg_query/issues/209
tables
=
PgQuery
.
parse
(
sql
).
tables
schemas
=
Database
::
GitlabSchema
.
table_schemas
(
tables
)
schemas
=
::
Gitlab
::
Database
::
GitlabSchema
.
table_schemas
(
tables
)
if
schemas
.
include?
(
:gitlab_ci
)
&&
schemas
.
include?
(
:gitlab_main
)
Thread
.
current
[
:has_cross_join_exception
]
=
true
...
...
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