***
Wartungsfenster jeden ersten Mittwoch vormittag im Monat
***
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VRE-Repository-Connector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Center for Research Data Management
VRE-Repository-Connector
Commits
2bfff439
Commit
2bfff439
authored
1 year ago
by
Moser, Maximilian
Browse files
Options
Downloads
Patches
Plain Diff
Fix creation of databases in DBRepo
parent
3801902b
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
vre_repository_connector/api/dbrepo.py
+15
-1
15 additions, 1 deletion
vre_repository_connector/api/dbrepo.py
with
15 additions
and
1 deletion
vre_repository_connector/api/dbrepo.py
+
15
−
1
View file @
2bfff439
...
@@ -14,6 +14,7 @@ from typing import List, Optional, Tuple
...
@@ -14,6 +14,7 @@ from typing import List, Optional, Tuple
import
requests
import
requests
from
dbrepo.api.dto
import
(
from
dbrepo.api.dto
import
(
CreateDatabase
,
CreateTable
,
CreateTable
,
CreateTableColumn
,
CreateTableColumn
,
CreateTableConstraints
,
CreateTableConstraints
,
...
@@ -101,6 +102,17 @@ class DBRepo(BaseWrapper):
...
@@ -101,6 +102,17 @@ class DBRepo(BaseWrapper):
else
:
else
:
raise
ValueError
(
f
"
Invalid DBRepo URL:
{
url
}
"
)
raise
ValueError
(
f
"
Invalid DBRepo URL:
{
url
}
"
)
def
_create_database
(
self
,
name
,
container_id
,
is_public
):
"""
Create the database.
"""
cdb
=
CreateDatabase
(
name
=
name
,
container_id
=
container_id
,
is_public
=
is_public
)
response
=
requests
.
post
(
url
=
f
"
{
self
.
client
.
endpoint
}
/api/database
"
,
json
=
json
.
loads
(
cdb
.
model_dump_json
()),
auth
=
(
self
.
client
.
username
,
self
.
client
.
password
),
)
return
response
.
json
()[
"
id
"
]
def
_create_table
(
def
_create_table
(
self
,
database_id
:
int
,
table_name
:
str
,
columns
:
List
[
CreateTableColumn
]
self
,
database_id
:
int
,
table_name
:
str
,
columns
:
List
[
CreateTableColumn
]
)
->
int
:
)
->
int
:
...
@@ -201,7 +213,9 @@ class DBRepo(BaseWrapper):
...
@@ -201,7 +213,9 @@ class DBRepo(BaseWrapper):
if
database_id
is
None
:
if
database_id
is
None
:
# TODO find better logic than this
# TODO find better logic than this
container_id
=
min
([
c
.
id
for
c
in
self
.
client
.
get_containers
()])
container_id
=
min
([
c
.
id
for
c
in
self
.
client
.
get_containers
()])
self
.
client
.
create_database
(
filename
,
container_id
=
container_id
)
database_id
=
self
.
_create_database
(
filename
,
container_id
=
container_id
,
is_public
=
True
)
table_id
=
self
.
_create_table
(
table_id
=
self
.
_create_table
(
database_id
,
table_name
or
filename
,
columns_from_analysis
(
analysis
)
database_id
,
table_name
or
filename
,
columns_from_analysis
(
analysis
)
...
...
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