Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
callidus
Machina Callida
Commits
70e003f0
Commit
70e003f0
authored
May 18, 2020
by
Konstantin Schulz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recreate database tables only if necessary
parent
a57fd5d5
Pipeline
#11603
passed with stages
in 3 minutes and 39 seconds
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
5 deletions
+11
-5
mc_backend/mcserver/app/__init__.py
mc_backend/mcserver/app/__init__.py
+5
-2
mc_backend/mcserver/app/services/databaseService.py
mc_backend/mcserver/app/services/databaseService.py
+3
-3
mc_backend/mcserver/config.py
mc_backend/mcserver/config.py
+3
-0
No files found.
mc_backend/mcserver/app/__init__.py
View file @
70e003f0
...
...
@@ -5,7 +5,7 @@ import sys
from
logging.handlers
import
RotatingFileHandler
from
threading
import
Thread
from
time
import
strftime
from
typing
import
Type
from
typing
import
Type
,
List
import
connexion
import
flask
from
connexion
import
FlaskApp
...
...
@@ -91,6 +91,9 @@ def init_app_common(cfg: Type[Config] = Config, is_csm: bool = False) -> Flask:
if
is_csm
:
from
mcserver.app.services.databaseService
import
DatabaseService
DatabaseService
.
init_db_alembic
()
tables
:
List
[
str
]
=
[
Config
.
DATABASE_TABLE_ALEMBIC
,
Config
.
DATABASE_TABLE_CORPUS
,
Config
.
DATABASE_TABLE_EXERCISE
,
Config
.
DATABASE_TABLE_UPDATEINFO
]
if
any
(
not
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
x
)
for
x
in
tables
):
db
.
create_all
()
from
mcserver.app.services.textService
import
TextService
TextService
.
init_proper_nouns_list
()
...
...
mc_backend/mcserver/app/services/databaseService.py
View file @
70e003f0
...
...
@@ -42,7 +42,7 @@ class DatabaseService:
@
staticmethod
def
init_db_corpus
()
->
None
:
"""Initializes the corpus list if it is not already there and up to date."""
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
"
Co
rpus"
):
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
Co
nfig
.
DATABASE_TABLE_CORPUS
):
CorpusService
.
existing_corpora
=
db
.
session
.
query
(
Corpus
).
all
()
db
.
session
.
commit
()
urn_dict
:
Dict
[
str
,
int
]
=
{
v
.
source_urn
:
i
for
i
,
v
in
enumerate
(
CorpusService
.
existing_corpora
)}
...
...
@@ -66,7 +66,7 @@ class DatabaseService:
@
staticmethod
def
init_db_update_info
()
->
None
:
"""Initializes update entries for all resources that have not yet been created."""
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
"UpdateInfo"
):
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
Config
.
DATABASE_TABLE_UPDATEINFO
):
for
rt
in
ResourceType
:
ui_cts
:
UpdateInfo
=
db
.
session
.
query
(
UpdateInfo
).
filter_by
(
resource_type
=
rt
.
name
).
first
()
if
ui_cts
is
None
:
...
...
@@ -93,7 +93,7 @@ class DatabaseService:
@
staticmethod
def
update_exercises
(
is_csm
:
bool
)
->
None
:
"""Deletes old exercises."""
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
"Exercise"
):
if
db
.
engine
.
dialect
.
has_table
(
db
.
engine
,
Config
.
DATABASE_TABLE_EXERCISE
):
exercises
:
List
[
Exercise
]
=
db
.
session
.
query
(
Exercise
).
all
()
now
:
datetime
=
datetime
.
utcnow
()
for
exercise
in
exercises
:
...
...
mc_backend/mcserver/config.py
View file @
70e003f0
...
...
@@ -58,6 +58,9 @@ class Config(object):
CUSTOM_CORPUS_VIVA_URN
=
"urn:custom:latinLit:viva.lat"
CUSTOM_CORPUS_PROIEL_URN_TEMPLATE
=
"urn:custom:latinLit:proiel.{0}.lat"
DATABASE_TABLE_ALEMBIC
=
"alembic_version"
DATABASE_TABLE_CORPUS
=
"Corpus"
DATABASE_TABLE_EXERCISE
=
"Exercise"
DATABASE_TABLE_UPDATEINFO
=
"UpdateInfo"
DATABASE_URL_DOCKER
=
"postgresql://postgres@db:5432/"
DATABASE_URL_LOCAL
=
"postgresql://postgres@0.0.0.0:5432/postgres"
DATABASE_URL_SQLITE
=
f
"sqlite:///
{
os
.
path
.
join
(
basedir
,
'app.db'
)
}
"
...
...
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