Browse Source

initializing database will delete existing sqlite file

php2python
Holger Frey 7 years ago
parent
commit
ae6cbac58d
  1. 6
      ordr2/scripts/initializedb.py

6
ordr2/scripts/initializedb.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import os
import sys
import transaction
from urllib.parse import urlparse
from pyramid.paster import (
get_appsettings,
@ -33,6 +34,11 @@ def main(argv=sys.argv): @@ -33,6 +34,11 @@ def main(argv=sys.argv):
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
# remove an existing sqlite database to issue a restart
database_url = urlparse(settings['sqlalchemy.url'])
if database_url.scheme == 'sqlite' and os.path.isfile(database_url.path):
os.remove(path)
engine = get_engine(settings)
Base.metadata.create_all(engine)