BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0c62b494
Unverified
Commit
0c62b494
authored
Feb 06, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset column information after the schema is migrated in MigrationsHelpers.schema_migrate_up!
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
826105df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
19 deletions
+15
-19
deserialize_merge_request_diffs_and_commits_spec.rb
...ation/deserialize_merge_request_diffs_and_commits_spec.rb
+0
-4
populate_merge_request_metrics_with_events_data_spec.rb
...n/populate_merge_request_metrics_with_events_data_spec.rb
+0
-4
convert_custom_notification_settings_to_columns_spec.rb
...s/convert_custom_notification_settings_to_columns_spec.rb
+2
-2
migrations_helpers.rb
spec/support/migrations_helpers.rb
+13
-9
No files found.
spec/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits_spec.rb
View file @
0c62b494
...
...
@@ -15,10 +15,6 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
.
to
receive
(
:commits_count
=
).
and_return
(
nil
)
end
after
do
[
Project
,
MergeRequest
,
MergeRequestDiff
].
each
(
&
:reset_column_information
)
end
def
diffs_to_hashes
(
diffs
)
diffs
.
as_json
(
only:
Gitlab
::
Git
::
Diff
::
SERIALIZE_KEYS
).
map
(
&
:with_indifferent_access
)
end
...
...
spec/lib/gitlab/background_migration/populate_merge_request_metrics_with_events_data_spec.rb
View file @
0c62b494
...
...
@@ -7,10 +7,6 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData,
.
to
receive
(
:commits_count
=
).
and_return
(
nil
)
end
after
do
[
Project
,
MergeRequest
,
MergeRequestDiff
].
each
(
&
:reset_column_information
)
end
describe
'#perform'
do
let
(
:mr_with_event
)
{
create
(
:merge_request
)
}
let!
(
:merged_event
)
{
create
(
:event
,
:merged
,
target:
mr_with_event
)
}
...
...
spec/migrations/convert_custom_notification_settings_to_columns_spec.rb
View file @
0c62b494
...
...
@@ -21,7 +21,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events
[
event
]
=
true
end
user
=
build
(
:user
).
becomes
(
user_class
).
tap
(
&
:save!
)
user
=
user_class
.
create!
(
email:
"user-
#{
SecureRandom
.
hex
}
@example.org"
,
username:
"user-
#{
SecureRandom
.
hex
}
"
,
encrypted_password:
'12345678'
)
create_params
=
{
user_id:
user
.
id
,
level:
params
[
:level
],
events:
events
}
notification_setting
=
described_class
::
NotificationSetting
.
create
(
create_params
)
...
...
@@ -37,7 +37,7 @@ describe ConvertCustomNotificationSettingsToColumns, :migration do
events
[
event
]
=
true
end
user
=
build
(
:user
).
becomes
(
user_class
).
tap
(
&
:save!
)
user
=
user_class
.
create!
(
email:
"user-
#{
SecureRandom
.
hex
}
@example.org"
,
username:
"user-
#{
SecureRandom
.
hex
}
"
,
encrypted_password:
'12345678'
)
create_params
=
events
.
merge
(
user_id:
user
.
id
,
level:
params
[
:level
])
notification_setting
=
described_class
::
NotificationSetting
.
create
(
create_params
)
...
...
spec/support/migrations_helpers.rb
View file @
0c62b494
...
...
@@ -15,18 +15,22 @@ module MigrationsHelpers
ActiveRecord
::
Migrator
.
migrations
(
migrations_paths
)
end
def
reset_column_in_migration_models
def
clear_schema_cache!
ActiveRecord
::
Base
.
connection_pool
.
connections
.
each
do
|
conn
|
conn
.
schema_cache
.
clear!
end
end
described_class
.
constants
.
sort
.
each
do
|
name
|
const
=
described_class
.
const_get
(
name
)
def
reset_column_in_all_models
clear_schema_cache!
if
const
.
is_a?
(
Class
)
&&
const
<
ActiveRecord
::
Base
const
.
reset_column_information
end
end
# Reset column information for the most offending classes **after** we
# migrated the schema up, otherwise, column information could be outdated
ActiveRecord
::
Base
.
descendants
.
each
{
|
klass
|
klass
.
reset_column_information
}
# Without that, we get errors because of missing attributes, e.g.
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
ApplicationSetting
.
define_attribute_methods
end
def
previous_migration
...
...
@@ -45,7 +49,7 @@ module MigrationsHelpers
migration_schema_version
)
end
reset_column_in_
migration
_models
reset_column_in_
all
_models
end
def
schema_migrate_up!
...
...
@@ -53,7 +57,7 @@ module MigrationsHelpers
ActiveRecord
::
Migrator
.
migrate
(
migrations_paths
)
end
reset_column_in_
migration
_models
reset_column_in_
all
_models
end
def
disable_migrations_output
...
...
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