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
c0dc8634
Commit
c0dc8634
authored
Sep 15, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure filled file_store on packages_package_files
parent
5f5c0dae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
0 deletions
+74
-0
db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb
...200915185707_ensure_filled_file_store_on_package_files.rb
+33
-0
db/schema_migrations/20200915185707
db/schema_migrations/20200915185707
+1
-0
spec/migrations/ensure_filled_file_store_on_package_files_spec.rb
...rations/ensure_filled_file_store_on_package_files_spec.rb
+40
-0
No files found.
db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb
0 → 100644
View file @
c0dc8634
# frozen_string_literal: true
class
EnsureFilledFileStoreOnPackageFiles
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
BACKGROUND_MIGRATION_CLASS
=
'SetNullPackageFilesFileStoreToLocalValue'
BATCH_SIZE
=
5_000
LOCAL_STORE
=
1
# equal to ObjectStorage::Store::LOCAL
DOWNTIME
=
false
disable_ddl_transaction!
module
Packages
class
PackageFile
<
ActiveRecord
::
Base
self
.
table_name
=
'packages_package_files'
include
::
EachBatch
end
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
BACKGROUND_MIGRATION_CLASS
)
# Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low.
Packages
::
PackageFile
.
where
(
file_store:
nil
).
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
,
index
|
batch
.
update_all
(
file_store:
LOCAL_STORE
)
end
end
def
down
# no-op
end
end
db/schema_migrations/20200915185707
0 → 100644
View file @
c0dc8634
e1ae80d6f0a6372bb329d45257d9a0a8ca5b6a83718d2a10ee295b8c4c97f60e
\ No newline at end of file
spec/migrations/ensure_filled_file_store_on_package_files_spec.rb
0 → 100644
View file @
c0dc8634
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200915185707_ensure_filled_file_store_on_package_files.rb'
)
RSpec
.
describe
EnsureFilledFileStoreOnPackageFiles
,
schema:
20200910175553
do
let!
(
:packages_package_files
)
{
table
(
:packages_package_files
)
}
let!
(
:packages_packages
)
{
table
(
:packages_packages
)
}
let!
(
:namespaces
)
{
table
(
:namespaces
)
}
let!
(
:projects
)
{
table
(
:projects
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let!
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let!
(
:package
)
{
packages_packages
.
create!
(
project_id:
project
.
id
,
name:
'bar'
,
package_type:
1
)
}
before
do
constraint_name
=
'check_4c5e6bb0b3'
# In order to insert a row with a NULL to fill.
ActiveRecord
::
Base
.
connection
.
execute
"ALTER TABLE packages_package_files DROP CONSTRAINT
#{
constraint_name
}
"
@file_store_1
=
packages_package_files
.
create!
(
file_store:
1
,
file_name:
'foo_1'
,
file:
'foo_1'
,
package_id:
package
.
id
)
@file_store_2
=
packages_package_files
.
create!
(
file_store:
2
,
file_name:
'foo_2'
,
file:
'foo_2'
,
package_id:
package
.
id
)
@file_store_nil
=
packages_package_files
.
create!
(
file_store:
nil
,
file_name:
'foo_nil'
,
file:
'foo_nil'
,
package_id:
package
.
id
)
# revert DB structure
ActiveRecord
::
Base
.
connection
.
execute
"ALTER TABLE packages_package_files ADD CONSTRAINT
#{
constraint_name
}
CHECK ((file_store IS NOT NULL)) NOT VALID"
end
it
'correctly migrates nil file_store to 1'
do
migrate!
@file_store_1
.
reload
@file_store_2
.
reload
@file_store_nil
.
reload
expect
(
@file_store_1
.
file_store
).
to
eq
(
1
)
# unchanged
expect
(
@file_store_2
.
file_store
).
to
eq
(
2
)
# unchanged
expect
(
@file_store_nil
.
file_store
).
to
eq
(
1
)
# nil => 1
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