from app import app, db from sqlalchemy.sql import func game_player = db.Table('game_player', db.Column('game_id', db.Integer, db.ForeignKey('game.id')), db.Column('player_id', db.Integer, db.ForeignKey('player.id')), db.Column('role', db.String(16)) ) class Game(db.Model): __tablename__ = 'game' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True, unique=True, nullable=False) password_hash = db.Column(db.String(128), nullable=False) state = db.Column(db.Integer, default='1') start_time = db.Column(db.DateTime) end_time = db.Column(db.DateTime) players = relationship( 'player', secondary=game_player, back_populates='games') class Player(db.Model): __tablename = 'player' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), unique=True, nullable=False) auth_hash = db.Column(db.String(128), unique=True, nullable=False) password_hash = db.Column(db.String(128)) games = relationship( 'game', secondary=game_player, back_populates='players') #start_time = db.Column(db.DateTime, server_default=func.now())