Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gerion Entrup
brainzfs
Commits
05ea5ffc
Commit
05ea5ffc
authored
Aug 30, 2016
by
Gerion Entrup
Browse files
restructuring: move schema initialization into model
parent
924ac22f
Changes
2
Hide whitespace changes
Inline
Side-by-side
brainzfs.py
View file @
05ea5ffc
...
...
@@ -4,9 +4,10 @@ import argparse
import
sys
import
logging
#workaround for sqlite pseudo concurrency
#remove it once python supports fully concurrency in sqlite
#
workaround for sqlite pseudo concurrency
#
remove it once python supports fully concurrency in sqlite
import
sqlitequeue
import
model
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
,
scoped_session
...
...
@@ -15,8 +16,6 @@ from sqlalchemy.pool import StaticPool
from
collector
import
Collector
from
translator
import
Translator
from
walker
import
Walker
from
mbdata.utils
import
patch_model_schemas
,
NO_SCHEMAS
from
model
import
patch_recording
,
Base
class
Main
:
...
...
@@ -33,9 +32,7 @@ class Main:
connect_args
=
{
'check_same_thread'
:
False
},
#echo = True,
poolclass
=
StaticPool
)
patch_model_schemas
(
NO_SCHEMAS
)
patch_recording
()
Base
.
metadata
.
create_all
(
engine
)
model
.
init_database
(
engine
)
session_factory
=
sessionmaker
(
bind
=
engine
)
session
=
scoped_session
(
session_factory
)
if
database
==
'sqlite:///'
:
...
...
model.py
View file @
05ea5ffc
from
sqlalchemy
import
Column
,
Integer
,
String
from
mbdata.utils
import
patch_model_schemas
,
NO_SCHEMAS
from
mbdata.models
import
Base
,
Recording
class
BrainzFS
(
Base
):
__tablename__
=
'brainzfs'
id
=
Column
(
Integer
,
primary_key
=
True
)
schemaversion
=
Column
(
Integer
,
nullable
=
False
)
programversion
=
Column
(
Integer
,
nullable
=
False
)
def
patch_recording
():
# store the path of the file
...
...
@@ -10,10 +18,11 @@ def patch_recording():
# store the mbid written in the file
setattr
(
Recording
,
'fgid'
,
Column
(
String
,
nullable
=
False
))
def
init_database
(
engine
):
patch_model_schemas
(
NO_SCHEMAS
)
patch_recording
()
Base
.
metadata
.
create_all
(
engine
)
class
BrainzFS
(
Base
):
__tablename__
=
'brainzfs'
id
=
Column
(
Integer
,
primary_key
=
True
)
schemaversion
=
Column
(
Integer
,
nullable
=
False
)
programversion
=
Column
(
Integer
,
nullable
=
False
)
Write
Preview
Supports
Markdown
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