first commit
This commit is contained in:
commit
52145ecabf
10 changed files with 538 additions and 0 deletions
36
initDb.py
Normal file
36
initDb.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import os
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
from initSchemas import initClassesFromSchemas, Base
|
||||
|
||||
|
||||
|
||||
# Database Initialization
|
||||
def initDb(_production, schemaDir):
|
||||
"""Initialize the database.
|
||||
"""
|
||||
|
||||
# Initialize the classes from the schemas
|
||||
print('Initializing the classes from the schemas...')
|
||||
if not initClassesFromSchemas(schemaDir):
|
||||
print('Cannot initialize database. No schemas found.')
|
||||
return (False, False)
|
||||
|
||||
if _production:
|
||||
dbName = 'database.db'
|
||||
else:
|
||||
dbName = 'test.db'
|
||||
|
||||
# Get the directory of the script
|
||||
dirPath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# Create the path of the database file
|
||||
dbPath = os.path.join(dirPath, dbName)
|
||||
|
||||
engine = create_engine(f'sqlite:///{dbPath}')
|
||||
metadata = MetaData()
|
||||
|
||||
# Create all tables in the engine
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
print('Database initialized.')
|
||||
return engine, metadata
|
||||
Loading…
Add table
Add a link
Reference in a new issue