Commit 05ea5ffc authored by Gerion Entrup's avatar Gerion Entrup
Browse files

restructuring: move schema initialization into model

parent 924ac22f
......@@ -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:///':
......
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment