From 9aecbff6a9d631ec45aa03fb0d033a86de436d72 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Mon, 6 Jul 2020 21:41:41 +0200 Subject: [PATCH] Change collum game_player.role to enum --- app/models.py | 8 ++++---- .../68009992b106_update_up_to_1_3_association_tables.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models.py b/app/models.py index ed04440..58f3e19 100644 --- a/app/models.py +++ b/app/models.py @@ -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): __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): '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( diff --git a/migrations/versions/68009992b106_update_up_to_1_3_association_tables.py b/migrations/versions/68009992b106_update_up_to_1_3_association_tables.py index 66b70c8..dc8e108 100644 --- a/migrations/versions/68009992b106_update_up_to_1_3_association_tables.py +++ b/migrations/versions/68009992b106_update_up_to_1_3_association_tables.py @@ -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(): 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')