class Publisher(db.Model): id = db.Column(db.Integer, primary_key=True) publisher_name = db.Column(db.String(20), nullable=False) def __init__(self, publisher_name): self.publisher_name = publisher_name def __repr__(self): return f"Publisher('{self.publisher_name}')"
class Run(db.Model): platform_id = db.Column(db.Integer, db.ForeignKey('platform.id'), primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('game.id'), primary_key=True) def __init__(self, platform_id, game_id): self.platform_id = platform_id self.game_id = game_id def __repr__(self): return f"Run('{self.platform_id}', '{self.game_id}')"
class Return(db.Model): id = db.Column(db.Integer, primary_key=True) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'), nullable=False) date = db.Column(db.Date, nullable=False) def __init__(self, customer_id, date): self.customer_id = customer_id self.date = date def __repr__(self): return f"Return('{self.date}')"
class Odetails(db.Model): order_id = db.Column(db.Integer, db.ForeignKey('order.id'), primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('game.id'), primary_key=True) qty = db.Column(db.Integer) def __init__(self, order_id, game_id, qty): self.order_id = order_id self.game_id = game_id self.qty = qty def __repr__(self): return f"Odetails('{self.qty}')"
class Order(db.Model): id = db.Column(db.Integer, primary_key=True) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'), nullable=False) date = db.Column(db.DateTime, nullable=False) order_details = db.relationship("Odetails", cascade="all, delete-orphan") def __init__(self, customer_id, date): self.customer_id = customer_id self.date = date def __repr__(self): return f"Order('{self.customer_id}', '{self.date}')"
class Platform(db.Model): id = db.Column(db.Integer, primary_key=True) platform_name = db.Column(db.String(50), nullable=False) release_date = db.Column(db.Date, nullable=False) price = db.Column(db.Numeric(4, 2), nullable=False) runs = db.relationship("Run", cascade="all, delete-orphan") def __init__(self, platform_name, release_date, price): self.platform_name = platform_name self.release_date = release_date self.price = price def __repr__(self): return f"Game('{self.platform_name}', '{self.release_date}', '{self.price}')"
class Purchase(db.Model): id = db.Column(db.Integer, primary_key=True) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id')) date = db.Column(db.DateTime, nullable=False) game_id = db.Column(db.Integer, db.ForeignKey('game.id')) qty = db.Column(db.Integer) def __init__(self, customer_id, date, game_id, qty): self.customer_id = customer_id self.date = date self.game_id = game_id self.qty = qty def __repr__(self): return f"Purchase('{self.customer_id}', '{self.date}', '{self.game_id}', '{self.qty}')"
class Customer(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) balance = db.Column(db.Numeric(4, 2)) orders = db.relationship("Purchase", cascade="all, delete-orphan") returns = db.relationship("Return", cascade="all, delete-orphan") __table_args__ = (CheckConstraint(balance >= 0, name='check_bar_positive'), {}) def __init__(self, username, email, password, balance): self.username = username self.email = email self.password = password self.balance = balance def __repr__(self): return f"Customer('{self.username}', '{self.email}', '{self.balance}')"
class Tenant(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) access = db.Column(db.Integer, nullable=False) def __init__(self, username, email, password, access=ACCESS['tenant']): self.name = username self.email = email self.password = password self.access = access def is_admin(self): return self.access == ACCESS['admin'] def allowed(self, access_level): return self.access >= access_level def __repr__(self): return f"Customer('{self.name}', '{self.email}')"
class Ticket(db.Model): id = db.Column(db.Integer, primary_key=True) tenant_email = db.Column(db.String(120), db.ForeignKey("tenant.email")) room_id = db.Column(db.Integer, nullable=False) build_id = db.Column(db.Integer, nullable=False) mtype = db.Column(db.String(40), nullable=False) submitdate = db.Column(db.Date, nullable=False) resolvedate = db.Column(db.Date) description = db.Column(db.String(720), nullable=False) def __init__(self, email, room_id, build_id, mtype, description, submitdate, resolvedate): self.tenant_email=email self.room_id=room_id self.build_id=build_id self.mtype=mtype self.description=description self.submitdate=submitdate self.resolvedate=resolvedate
class Game(db.Model): id = db.Column(db.Integer, primary_key=True) game_name = db.Column(db.String(50), nullable=False) genre = db.Column(db.String(50), nullable=False) release_date = db.Column(db.Date, nullable=False) price = db.Column(db.Numeric(4, 2), nullable=False) description = db.Column(db.String(200), nullable=False) publisher_id = db.Column(db.Integer, db.ForeignKey('publisher.id')) runs = db.relationship("Run", cascade="all, delete-orphan") def __init__(self, game_name, genre, release_date, price, description, publisher_id): self.game_name = game_name self.genre = genre self.release_date = release_date self.price = price self.description = description self.publisher_id = publisher_id def __repr__(self): return f"Game('{self.game_name}', '{self.genre}', '{self.release_date}', '{self.price}', '{self.description}', '{self.publisher_id}')"