from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

import config

SQLALCHEMY_DATABASE_URI = f'mysql-pymysql://{config.MYSQL_USER}:{config.MYSQL_PASSWORD}:{config.MYSQL_HOST}'
engine = create_engine(
    SQLALCHEMY_DATABASE_URI
)

engine.execute(f'CREATE DATABASE IF NOT EXISTS {config.MYSQL_DATABASE}')
engine.execute(f'USE {config.MYSQL_DATABASE}')

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()