-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
22 lines (16 loc) · 756 Bytes
/
Copy pathdatabase.py
File metadata and controls
22 lines (16 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base
import os
DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///todo.db")
# Render sets DATABASE_URL with 'postgres://' but SQLAlchemy needs 'postgresql://'
if DATABASE_URL.startswith("postgres://"):
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1)
engine = create_engine(DATABASE_URL, echo=True)
# Creates an engine in which the databases will be stored
SessionLocal = sessionmaker(bind=engine) #This creates a 'factory' for sessions
def create_db():
Base.metadata.create_all(engine)
#Creates the databases of the Task and User classes and transfers them into todo.db
if __name__ == "__main__":
create_db()