Define foreign keys in models
This commit is contained in:
parent
d44f5c732e
commit
868903b989
|
@ -1,7 +1,8 @@
|
|||
from database import Base
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Text, Enum, text
|
||||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, Integer, String, Text, text
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from database import Base
|
||||
|
||||
|
||||
class Users(Base):
|
||||
__tablename__ = "users"
|
||||
|
@ -15,7 +16,7 @@ class Users(Base):
|
|||
gender = Column(Integer)
|
||||
mobile = Column(String(255))
|
||||
user_image = Column(String(255))
|
||||
city_id = Column(Integer)
|
||||
city_id = Column(Integer, ForeignKey("cities.id"))
|
||||
user_type = Column(Integer)
|
||||
otp = Column(String(255))
|
||||
otp_valid_time = Column(DateTime)
|
||||
|
@ -88,11 +89,11 @@ class Games(Base):
|
|||
date_time = Column(DateTime)
|
||||
price = Column(String(100))
|
||||
description = Column(Text)
|
||||
user_id = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
gender = Column(Enum("1", "2", "3"))
|
||||
city_id = Column(Integer)
|
||||
venue_id = Column(Integer)
|
||||
sports_id = Column(Integer)
|
||||
city_id = Column(Integer, ForeignKey("cities.id"))
|
||||
venue_id = Column(Integer, ForeignKey("venues.id"))
|
||||
sports_id = Column(Integer, ForeignKey("sports.id"))
|
||||
no_of_player = Column(Integer)
|
||||
min_player = Column(Integer)
|
||||
already_player = Column(Integer)
|
||||
|
@ -147,8 +148,8 @@ class Payments(Base):
|
|||
__tablename__ = "payments"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer)
|
||||
game_id = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
game_id = Column(Integer, ForeignKey("games.id"))
|
||||
amount = Column(Integer)
|
||||
token = Column(String(100))
|
||||
charge_id = Column(String(200))
|
||||
|
@ -192,8 +193,8 @@ class PlayerAvailabilities(Base):
|
|||
__tablename__ = "player_availabilities"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
game_id = Column(Integer)
|
||||
player_id = Column(Integer)
|
||||
game_id = Column(Integer, ForeignKey("games.id"))
|
||||
player_id = Column(Integer, ForeignKey("users.id"))
|
||||
status = Column(Integer)
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
@ -210,8 +211,8 @@ class PlayerCancelGames(Base):
|
|||
__tablename__ = "player_cancel_games"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
player_id = Column(Integer)
|
||||
game_id = Column(Integer)
|
||||
player_id = Column(Integer, ForeignKey("users.id"))
|
||||
game_id = Column(Integer, ForeignKey("games.id"))
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
||||
|
@ -226,8 +227,8 @@ class PurchaseGames(Base):
|
|||
__tablename__ = "purchase_games"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
game_id = Column(Integer)
|
||||
user_id = Column(Integer)
|
||||
game_id = Column(Integer, ForeignKey("games.id"))
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
pay_mode = Column(Integer)
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
@ -262,9 +263,9 @@ class Teams(Base):
|
|||
__tablename__ = "teams"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users_id"))
|
||||
team_id = Column(Enum("1", "2"))
|
||||
game_id = Column(Integer)
|
||||
game_id = Column(Integer, ForeignKey("games_id"))
|
||||
status = Column(Integer)
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
@ -282,9 +283,9 @@ class UserRatings(Base):
|
|||
__tablename__ = "user_ratings"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
game_id = Column(Integer)
|
||||
user_id = Column(Integer)
|
||||
player_id = Column(Integer)
|
||||
game_id = Column(Integer, ForeignKey("games_id"))
|
||||
user_id = Column(Integer, ForeignKey("users_id"))
|
||||
player_id = Column(Integer, ForeignKey("users_id"))
|
||||
rating = Column(String(100))
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
@ -302,8 +303,8 @@ class VenueImages(Base):
|
|||
__tablename__ = "venue_images"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
venue_id = Column(Integer)
|
||||
user_id = Column(Integer)
|
||||
venue_id = Column(Integer, ForeignKey("venues_id"))
|
||||
user_id = Column(Integer, ForeignKey("users_id"))
|
||||
image = Column(String(255))
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
@ -320,12 +321,12 @@ class Venues(Base):
|
|||
__tablename__ = "venues"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users_id"))
|
||||
address = Column(Text)
|
||||
latitude = Column(String(100))
|
||||
longitude = Column(String(100))
|
||||
name = Column(String(100))
|
||||
sports_id = Column(Integer)
|
||||
sports_id = Column(Integer, ForeignKey("sports_id"))
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
||||
|
@ -345,7 +346,7 @@ class ViewNews(Base):
|
|||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
news_id = Column(Integer)
|
||||
user_id = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users_id"))
|
||||
created = Column(DateTime, nullable=False, server_default=func.now())
|
||||
updated = Column(DateTime, nullable=True, onupdate=func.now())
|
||||
|
||||
|
|
Loading…
Reference in New Issue