Update app/models.py
This commit is contained in:
parent
9962b54521
commit
4a8e63eec1
1 changed files with 28 additions and 5 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
from sqlalchemy import Column, Integer, String, Float, Date
|
from sqlalchemy import Column, Integer, String, Float, Date, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
from app.database import Base
|
from app.database import Base
|
||||||
|
|
||||||
class Customer(Base):
|
class Customer(Base):
|
||||||
__tablename__ = "customers"
|
__tablename__ = "customers"
|
||||||
|
|
||||||
customer_id = Column(String(20), primary_key=True, index=True) # IDs are strings now
|
customer_id = Column(String(20), primary_key=True, index=True)
|
||||||
full_name = Column(String(100), index=True)
|
full_name = Column(String(100), index=True)
|
||||||
email = Column(String(100), unique=True)
|
email = Column(String(100), unique=True)
|
||||||
phone = Column(String(50))
|
phone = Column(String(50))
|
||||||
|
|
@ -22,13 +23,35 @@ class Customer(Base):
|
||||||
credit_score = Column(Integer)
|
credit_score = Column(Integer)
|
||||||
preferred_contact_method = Column(String(20))
|
preferred_contact_method = Column(String(20))
|
||||||
|
|
||||||
|
accounts = relationship("Account", back_populates="customer")
|
||||||
|
|
||||||
|
|
||||||
class Account(Base):
|
class Account(Base):
|
||||||
__tablename__ = "accounts"
|
__tablename__ = "accounts"
|
||||||
|
|
||||||
account_id = Column(String(20), primary_key=True, index=True) # IDs are strings now
|
account_id = Column(String(20), primary_key=True, index=True)
|
||||||
account_number = Column(String(20), unique=True, index=True)
|
account_number = Column(String(20), unique=True, index=True)
|
||||||
customer_id = Column(String(20)) # matches Customer.customer_id
|
customer_id = Column(String(20), ForeignKey("customers.customer_id"))
|
||||||
account_type = Column(String(20))
|
account_type = Column(String(20))
|
||||||
open_date = Column(Date)
|
open_date = Column(Date)
|
||||||
balance = Column(Float)
|
balance = Column(Float)
|
||||||
branch_id = Column(Integer)
|
branch_id = Column(Integer)
|
||||||
|
|
||||||
|
customer = relationship("Customer", back_populates="accounts")
|
||||||
|
transactions = relationship("Transaction", back_populates="account")
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction(Base):
|
||||||
|
__tablename__ = "transactions"
|
||||||
|
|
||||||
|
transaction_id = Column(String(30), primary_key=True, index=True)
|
||||||
|
account_id = Column(String(20), ForeignKey("accounts.account_id"))
|
||||||
|
branch_id = Column(Integer)
|
||||||
|
transaction_type = Column(String(50))
|
||||||
|
amount = Column(Float)
|
||||||
|
date = Column(Date)
|
||||||
|
balance_after = Column(Float)
|
||||||
|
vendor = Column(String(100))
|
||||||
|
transaction_location = Column(String(100))
|
||||||
|
|
||||||
|
account = relationship("Account", back_populates="transactions")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue