Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-core
Commits
6eea4a05
Verified
Commit
6eea4a05
authored
6 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
tests.db_testing: Add a function to read swh's db version
parent
386f8e20
No related branches found
Branches containing commit
No related tags found
1 merge request
!304
swh-db-init: Make the db initialization idempotent
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/core/tests/db_testing.py
+30
-1
30 additions, 1 deletion
swh/core/tests/db_testing.py
with
30 additions
and
1 deletion
swh/core/tests/db_testing.py
+
30
−
1
View file @
6eea4a05
# Copyright (C) 2015 The Software Heritage developers
# Copyright (C) 2015
-2018
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -13,6 +13,35 @@ from swh.core.utils import numfile_sortkey as sortkey
DB_DUMP_TYPES
=
{
'
.sql
'
:
'
psql
'
,
'
.dump
'
:
'
pg_dump
'
}
def
swh_db_version
(
dbname_or_service
):
"""
Retrieve the swh version if any. In case of the db not initialized,
this returns None. Otherwise, this returns the db
'
s version.
Args:
dbname_or_service (str): The db
'
s name or service
Returns:
Optional[Int]: Either the db
'
s version or None
"""
query
=
'
select version from dbversion order by dbversion desc limit 1
'
cmd
=
[
'
psql
'
,
'
--tuples-only
'
,
'
--no-psqlrc
'
,
'
--quiet
'
,
'
-v
'
,
'
ON_ERROR_STOP=1
'
,
"
--command=%s
"
%
query
,
dbname_or_service
,
]
print
(
'
cmd: %s
'
%
cmd
)
try
:
r
=
subprocess
.
run
(
cmd
,
check
=
True
,
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
,
stderr
=
None
)
result
=
int
(
r
.
stdout
.
strip
())
except
Exception
:
# db not initialized
result
=
None
return
result
def
pg_restore
(
dbname
,
dumpfile
,
dumptype
=
'
pg_dump
'
):
"""
Args:
...
...
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