Browse Source

Change collum game_player.role to enum

feature_tests
Rogier Neeleman 4 years ago
parent
commit
9aecbff6a9
  1. 8
      app/models.py
  2. 4
      migrations/versions/68009992b106_update_up_to_1_3_association_tables.py

8
app/models.py

@ -23,7 +23,7 @@ class GamePlayer(db.Model): @@ -23,7 +23,7 @@ class GamePlayer(db.Model):
__tablename__ = 'game_player'
game_id = db.Column(db.Integer, db.ForeignKey('game.id'), primary_key=True, nullable=False)
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key=True, nullable=False)
role = db.Column(db.Enum(Role), server_default=Role(0).name)
role = db.Column(db.Enum(Role), server_default=Role(0).name, nullable=False)
game = db.relationship('Game', back_populates='game_players')
player = db.relationship('Player', back_populates='player_games')
@ -57,14 +57,14 @@ class Game(db.Model): @@ -57,14 +57,14 @@ 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)
state = db.Column(db.Enum(GameState), server_default=GameState(1).name)
state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False)
start_time = db.Column(db.DateTime)
end_time = db.Column(db.DateTime)
game_players = db.relationship(
'GamePlayer',
back_populates='game',
cascade="save-update, merge, delete, delete-orphan")
players = association_proxy('game_players', 'player',
players = association_proxy('game_players', 'player',
creator=lambda player: GamePlayer(player=player)) # to enable game.players.append(player)
objectives = db.relationship(
'Objective',
@ -86,7 +86,7 @@ class Player(UserMixin, db.Model): @@ -86,7 +86,7 @@ class Player(UserMixin, db.Model):
'GamePlayer',
back_populates='player',
cascade='save-update, merge, delete, delete-orphan')
games = association_proxy('player_games', 'game',
games = association_proxy('player_games', 'game',
creator=lambda game: GamePlayer(game=game))
player_found_objectives = db.relationship(

4
migrations/versions/68009992b106_update_up_to_1_3_association_tables.py

@ -21,7 +21,7 @@ def upgrade(): @@ -21,7 +21,7 @@ def upgrade():
op.create_table('game',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.Column('state', sa.Enum('initiated', 'published', 'started', 'interrupted', 'finished', name='gamestate'), server_default='initiated', nullable=True),
sa.Column('state', sa.Enum('initiated', 'published', 'started', 'interrupted', 'finished', name='gamestate'), server_default='initiated', nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
@ -39,7 +39,7 @@ def upgrade(): @@ -39,7 +39,7 @@ def upgrade():
op.create_table('game_player',
sa.Column('game_id', sa.Integer(), nullable=False),
sa.Column('player_id', sa.Integer(), nullable=False),
sa.Column('role', sa.String(length=16), nullable=True),
sa.Column('role', sa.Enum('none', 'owner', 'hunter', 'bunny', name='role'), server_default='none', nullable=False),
sa.ForeignKeyConstraint(['game_id'], ['game.id'], ),
sa.ForeignKeyConstraint(['player_id'], ['player.id'], ),
sa.PrimaryKeyConstraint('game_id', 'player_id')

Loading…
Cancel
Save