Explorar o código

Add war related tables

JoostSijm %!s(int64=4) %!d(string=hai) anos
pai
achega
f82177803b
Modificáronse 2 ficheiros con 96 adicións e 0 borrados
  1. 56 0
      app/models.py
  2. 40 0
      migrations/versions/ae444ab1a42b_add_bloc.py

+ 56 - 0
app/models.py

@@ -127,6 +127,28 @@ class State(Base):
         backref=backref('state_capital', lazy='dynamic')
     )
 
+
+class Bloc(Base):
+    """Model for bloc"""
+    __tablename__ = 'bloc'
+    id = Column(Integer, primary_key=True)
+    name = Column(String)
+    state_id = Column(Integer, ForeignKey('state.id'))
+    state = relationship(
+        'State',
+        backref=backref('bloc_founders', lazy='dynamic')
+    )
+
+
+class BlocStates(Base):
+    """Model for bloc states"""
+    __tablename__ = 'bloc_states'
+    bloc_id = Column(Integer, ForeignKey('region.id'), primary_key=True)
+    state_id = Column(Integer, ForeignKey('state.id'), primary_key=True)
+    from_date_time = Column(DateTime, primary_key=True)
+    until_date_time = Column(DateTime)
+
+
 class Department(Base):
     """Model for department"""
     __tablename__ = 'department'
@@ -413,3 +435,37 @@ class PlayerTelegram(Base):
     telegram_id = Column(BigInteger, ForeignKey('telegram_account.id'), primary_key=True)
     from_date_time = Column(DateTime, primary_key=True)
     until_date_time = Column(DateTime)
+
+
+class War(Base):
+    """Model for war"""
+    __tablename__ = 'war'
+    id = Column(Integer, primary_key=True)
+    until_date_time = Column(DateTime)
+    war_type = Column(SmallInteger)
+    priority = Column(SmallInteger)
+    attacking_id = Column(Integer, ForeignKey('region.id'))
+    attacking = relationship(
+        'Region',
+        backref=backref('attacked_wars', lazy='dynamic')
+    )
+    defending_id = Column(Integer, ForeignKey('region.id'))
+    defending = relationship(
+        'Region',
+        backref=backref('defending_wars', lazy='dynamic')
+    )
+
+class war_stat(Base):
+    """Model for war stat"""
+    __tablename__ = 'war_stat'
+    id = Column(Integer, primary_key=True)
+    war_id = Column(Integer, ForeignKey('war.id'))
+    attack_damage = Column(BigInteger)
+    attack_military_base = Column(Integer)
+    attack_military_academy = Column(Integer)
+    defend_damage = Column(BigInteger)
+
+    war = relationship(
+        'War',
+        backref=backref('defending_wars', lazy='dynamic')
+    )

+ 40 - 0
migrations/versions/ae444ab1a42b_add_bloc.py

@@ -0,0 +1,40 @@
+"""add bloc
+
+Revision ID: ae444ab1a42b
+Revises: 95e16c281a76
+Create Date: 2020-03-02 12:54:46.854784
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'ae444ab1a42b'
+down_revision = '95e16c281a76'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    op.create_table('bloc',
+    sa.Column('id', sa.Integer(), nullable=False),
+    sa.Column('name', sa.String(), nullable=True),
+    sa.Column('state_id', sa.Integer(), nullable=True),
+    sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_bloc_state_id_state')),
+    sa.PrimaryKeyConstraint('id', name=op.f('pk_bloc'))
+    )
+    op.create_table('bloc_states',
+    sa.Column('bloc_id', sa.Integer(), nullable=False),
+    sa.Column('state_id', sa.Integer(), nullable=False),
+    sa.Column('from_date_time', sa.DateTime(), nullable=False),
+    sa.Column('until_date_time', sa.DateTime(), nullable=True),
+    sa.ForeignKeyConstraint(['bloc_id'], ['region.id'], name=op.f('fk_bloc_states_bloc_id_region')),
+    sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_bloc_states_state_id_state')),
+    sa.PrimaryKeyConstraint('bloc_id', 'state_id', 'from_date_time', name=op.f('pk_bloc_states'))
+    )
+
+
+def downgrade():
+    op.drop_table('bloc_states')
+    op.drop_table('bloc')