-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
37 lines (28 loc) · 1.27 KB
/
Copy pathdatabase.py
File metadata and controls
37 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sqlalchemy import create_engine, String, Integer, Column, Numeric, TIMESTAMP, func, ForeignKey
from sqlalchemy.orm import declarative_base, sessionmaker
import os
from dotenv import load_dotenv
load_dotenv()
Base = declarative_base()
url_bank = os.getenv("DATABASE_URL")
class Account(Base):
__tablename__ = "BankAccounts"
__table_args__ = {"schema": "Bank"}
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
full_name = Column(String)
gmail = Column(String, unique=True, index=True)
cpf = Column(String, unique=True)
username = Column(String, unique=True)
hashed_password = Column(String)
balance = Column(Numeric)
class Transactions(Base):
__tablename__ = "History"
__table_args__ = {"schema": "Bank"}
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
account_id = Column(Integer, ForeignKey("Bank.BankAccounts.id", ondelete="CASCADE"), nullable=False)
type = Column(String, nullable=False)
amount = Column(Numeric(10,2), nullable=False)
created_at = Column(TIMESTAMP, server_default=func.now())
description = Column(String)
engine = create_engine(url_bank)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)