Define foreign keys in models

This commit is contained in:
coolneng 2020-09-03 19:34:51 +02:00
parent d44f5c732e
commit 868903b989
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 26 additions and 25 deletions

View File

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