full import scripts
This commit is contained in:
parent
4d74913447
commit
34c9b1c0a9
136 changed files with 289629 additions and 10 deletions
14
initDb.py
14
initDb.py
|
|
@ -1,8 +1,11 @@
|
|||
import dotenv
|
||||
import os
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from initSchemas import initClassesFromSchemas, Base
|
||||
|
||||
|
||||
# Load the environment variables
|
||||
dotenv.load_dotenv()
|
||||
|
||||
# Database Initialization
|
||||
def initDb(_production, schemaDir):
|
||||
|
|
@ -16,9 +19,9 @@ def initDb(_production, schemaDir):
|
|||
return (False, False)
|
||||
|
||||
if _production:
|
||||
dbName = 'database.db'
|
||||
dbName = 'ngk'
|
||||
else:
|
||||
dbName = 'test.db'
|
||||
dbName = 'testngk'
|
||||
|
||||
# Get the directory of the script
|
||||
dirPath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
|
@ -26,11 +29,12 @@ def initDb(_production, schemaDir):
|
|||
# Create the path of the database file
|
||||
dbPath = os.path.join(dirPath, dbName)
|
||||
|
||||
engine = create_engine(f'sqlite:///{dbPath}')
|
||||
engine = create_engine(f'mysql+pymysql://{os.getenv("DB_USER")}:{os.getenv("DB_PASS")}@{os.getenv("DB_HOST")}/{os.getenv("DB_NAME")}', echo=False)
|
||||
metadata = MetaData()
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
# Create all tables in the engine
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
print('Database initialized.')
|
||||
return engine, metadata
|
||||
return engine, metadata, Session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue