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
67591afb
Commit
67591afb
authored
Jan 11, 2022
by
Thong Kuah
Committed by
Kamil Trzciński
Jan 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature flag
parent
4b3ddbd5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
5 deletions
+75
-5
app/models/concerns/cross_database_modification.rb
app/models/concerns/cross_database_modification.rb
+17
-5
config/feature_flags/development/track_gitlab_schema_in_current_transaction.yml
...evelopment/track_gitlab_schema_in_current_transaction.yml
+8
-0
spec/models/concerns/cross_database_modification_spec.rb
spec/models/concerns/cross_database_modification_spec.rb
+50
-0
No files found.
app/models/concerns/cross_database_modification.rb
View file @
67591afb
...
...
@@ -9,15 +9,27 @@ module CrossDatabaseModification
class_methods
do
def
transaction
(
**
options
,
&
block
)
super
(
**
options
)
do
if
connection
.
current_transaction
.
respond_to?
(
:add_gitlab_schema
)
&&
gitlab_schema
connection
.
current_transaction
.
add_gitlab_schema
(
gitlab_schema
)
end
if
track_gitlab_schema_in_current_transaction?
super
(
**
options
)
do
if
connection
.
current_transaction
.
respond_to?
(
:add_gitlab_schema
)
&&
gitlab_schema
connection
.
current_transaction
.
add_gitlab_schema
(
gitlab_schema
)
end
yield
yield
end
else
super
(
**
options
,
&
block
)
end
end
def
track_gitlab_schema_in_current_transaction?
return
false
unless
Feature
::
FlipperFeature
.
table_exists?
Feature
.
enabled?
(
:track_gitlab_schema_in_current_transaction
,
default_enabled: :yaml
)
rescue
ActiveRecord
::
NoDatabaseError
,
PG
::
ConnectionBad
false
end
def
gitlab_schema
case
self
.
name
when
'ActiveRecord::Base'
,
'ApplicationRecord'
...
...
config/feature_flags/development/track_gitlab_schema_in_current_transaction.yml
0 → 100644
View file @
67591afb
---
name
:
track_gitlab_schema_in_current_transaction
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76717
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/349944
milestone
:
'
14.7'
type
:
development
group
:
group::sharding
default_enabled
:
false
spec/models/concerns/cross_database_modification_spec.rb
View file @
67591afb
...
...
@@ -4,6 +4,56 @@ require 'spec_helper'
RSpec
.
describe
CrossDatabaseModification
do
describe
'.transaction'
do
def
assert_no_gitlab_schema_comment
(
log
)
include_arg
=
[
/gitlab_schema/
]
*
log
.
size
expect
(
log
).
not_to
include
(
*
include_arg
)
end
context
'feature flag disabled'
do
before
do
stub_feature_flags
(
track_gitlab_schema_in_current_transaction:
false
)
end
it
'does not add gitlab_schema comment'
do
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
ApplicationRecord
.
transaction
do
Project
.
first
end
end
expect
(
recorder
.
log
).
to
include
(
/SAVEPOINT/
,
/SELECT.*FROM "projects"/
,
/RELEASE SAVEPOINT/
)
assert_no_gitlab_schema_comment
(
recorder
.
log
)
end
end
context
'feature flag is not yet setup'
do
before
do
allow
(
Feature
::
FlipperFeature
).
to
receive
(
:table_exists?
).
and_raise
(
ActiveRecord
::
NoDatabaseError
)
end
it
'does not add gitlab_schema comment'
do
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
ApplicationRecord
.
transaction
do
Project
.
first
end
end
expect
(
recorder
.
log
).
to
include
(
/SAVEPOINT/
,
/SELECT.*FROM "projects"/
,
/RELEASE SAVEPOINT/
)
assert_no_gitlab_schema_comment
(
recorder
.
log
)
end
end
it
'adds gitlab_schema to the current transaction'
,
:aggregate_failures
do
recorder
=
ActiveRecord
::
QueryRecorder
.
new
do
ApplicationRecord
.
transaction
do
...
...
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