Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
df9b9003
Commit
df9b9003
authored
7 years ago
by
Harsha Kethineni
Browse files
Options
Downloads
Patches
Plain Diff
removed tests
parent
24f46a97
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/database.py
+4
-59
4 additions, 59 deletions
bin/database.py
with
4 additions
and
59 deletions
bin/database.py
+
4
−
59
View file @
df9b9003
...
...
@@ -19,7 +19,7 @@ from api.jobs.jobs import Job
from
api.jobs
import
gears
from
api.types
import
Origin
CURRENT_DATABASE_VERSION
=
30
# An int that is bumped when a new schema change is made
CURRENT_DATABASE_VERSION
=
28
# An int that is bumped when a new schema change is made
def
get_db_version
():
...
...
@@ -97,6 +97,7 @@ def process_cursor(cursor, closure):
failed
=
False
cursor_size
=
cursor
.
count
()
cursor_index
=
0
next_percent
=
5.0
percent_increment
=
5
if
(
cursor_size
<
20
):
...
...
@@ -105,11 +106,12 @@ def process_cursor(cursor, closure):
if
(
cursor_size
<
4
):
next_percent
=
50.0
percent_increment
=
50
for
cursor_index
,
document
in
enumerate
(
cursor
)
:
for
document
in
cursor
:
if
100
*
(
cursor_index
/
cursor_size
)
>=
next_percent
:
logging
.
info
(
'
{} percent complete ...
'
.
format
(
next_percent
))
next_percent
=
next_percent
+
percent_increment
result
=
closure
(
document
)
cursor_index
=
cursor_index
+
1
if
result
!=
True
:
failed
=
True
logging
.
info
(
'
Upgrade failed:
'
+
str
(
result
))
...
...
@@ -1019,63 +1021,6 @@ def upgrade_to_28():
config
.
db
.
sessions
.
update
({
'
_id
'
:
x
[
'
_id
'
]},
{
'
$set
'
:
{
'
subject.age
'
:
int_age
}})
def
upgrade_to_29_closure
(
job
):
gear
=
config
.
db
.
gears
.
find_one
({
'
_id
'
:
bson
.
ObjectId
(
job
[
'
gear_id
'
])},
{
'
gear.name
'
:
1
})
# This logic WILL NOT WORK in parallel mode
if
gear
is
None
:
return
True
if
gear
.
get
(
'
gear
'
,
{}).
get
(
'
name
'
,
None
)
is
None
:
logging
.
info
(
'
No gear found for job
'
+
str
(
job
[
'
_id
'
]))
return
True
# This logic WILL NOT WORK in parallel mode
gear_name
=
gear
[
'
gear
'
][
'
name
'
]
# Update doc
result
=
config
.
db
.
jobs
.
update_one
({
'
_id
'
:
job
[
'
_id
'
]},
{
'
$push
'
:
{
'
tags
'
:
gear_name
}})
if
result
.
modified_count
==
1
:
return
True
else
:
return
'
Parallel failed: update doc
'
+
str
(
job
[
'
_id
'
])
+
'
resulted modified
'
+
str
(
result
.
modified_count
)
def
upgrade_to_29
():
"""
scitran/core #777
Logs progress on processing the cursor
"""
cursor
=
config
.
db
.
jobs
.
find
({})
process_cursor
(
cursor
,
upgrade_to_29_closure
)
# Below is insert command for 10000 jobs, they don't have many of the fields though
config
.
db
.
jobs
.
insert
(({
'
name
'
:
i
,
'
gear_id
'
:
bson
.
objectid
.
ObjectId
()}
for
i
in
xrange
(
10000
)))
cursor
=
config
.
db
.
jobs
.
find
({})
process_cursor
(
cursor
,
upgrade_to_29_closure
)
config
.
db
.
jobs
.
remove
()
def
upgrade_to_30_closure
(
user
):
for
avatar
in
user
.
get
(
avatars
):
if
avatar
[
4
]
!=
'
s
'
:
user
.
remove
(
avatar
)
def
upgrade_to_30
():
"""
Enforces HTTPS urls for avatars, removes them if they are not HTTPS
"""
cursor
=
config
.
db
.
users
.
find
({})
process_cursor
(
cursor
,
upgrade_to_30_closure
)
def
upgrade_schema
():
"""
Upgrades db to the current schema version
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment