Skip to content

Commit

Permalink
Remove foreign key constraint from teams table
Browse files Browse the repository at this point in the history
  • Loading branch information
Antar1011 committed Sep 22, 2016
1 parent e6e208c commit bd30fa6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions onix/backend/sql/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ class TeamMember(Base):
ORM representation of a team member. Note that the "idx" column refers to
the position of the member after sorting the team by SID, *not* its position
on a team during battle.
.. note ::
The sid column should really be a foreign key in the movesets table, but
it's not so as to allow movesets and battle info to be written to
the DB in any order. Be aware, and take special care to preserve
preserve the integrity of this table.
"""
__tablename__ = 'teams'

tid = sa.Column(sa.String(512), primary_key=True)
idx = sa.Column(sa.SmallInteger, primary_key=True)
sid = sa.Column(sa.String(512), sa.ForeignKey('movesets.id'),
nullable=False)
sid = sa.Column(sa.String(512), nullable=False)


@ignore_inserts
Expand Down
41 changes: 41 additions & 0 deletions onix/tests/backend/sql/test_sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,45 @@ def test_batch_size(self, engine, session_maker, sceptile, chimchar):
assert 0 == len(list(moveset_sink.session))


@pytest.mark.usefixtures('initialize_db')
class TestBattleInfoSink(object):

@staticmethod
@pytest.fixture()
def players():
return [Player('alice', {'l': 57, 'w': 16, 't': 0}),
Player('bob', {'l': 24, 'w': 23, 't': 4}),
Player('eve', {'l': 68, 'w': 52, 't': 7})]

@staticmethod
@pytest.fixture()
def teams():
return [['7e3a6e07', '9cb1e085', 'ca66695c'],
['cedfdf7a', 'd92e68ec', '9cb1e085'],
['9cb1e085', '7e3a6e07', 'ca66695c']]


@staticmethod
@pytest.fixture()
def battle_infos(players, teams):
return [BattleInfo(1, 'ubers', datetime.date(2016, 9, 22),
players[:2], teams[:2],
14, 'normal'),
BattleInfo(2, 'ubers', datetime.date(2016, 9, 22),
players[1:], teams[1:],
18, 'forfeit')]

def test_insert_one(self, engine, session_maker, battle_infos):

with sinks.BattleInfoSink(session_maker) as battle_info_sink:
battle_info_sink.store_battle_info(battle_infos[0])

with engine.connect() as conn:
result = conn.execute('SELECT COUNT(*) FROM teams')
assert (6,) == result.fetchone()






0 comments on commit bd30fa6

Please sign in to comment.