e6577173fe0f_add_new_tables.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """add new tables
  2. Revision ID: e6577173fe0f
  3. Revises: 431b9069abfc
  4. Create Date: 2019-09-03 10:38:14.530991
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = 'e6577173fe0f'
  10. down_revision = '431b9069abfc'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. op.create_table('department',
  15. sa.Column('id', sa.Integer(), nullable=False),
  16. sa.Column('name', sa.String(), nullable=True),
  17. sa.Column('department_type', sa.Integer(), nullable=True),
  18. sa.PrimaryKeyConstraint('id', name=op.f('pk_department'))
  19. )
  20. op.create_table('party',
  21. sa.Column('id', sa.Integer(), nullable=False),
  22. sa.Column('name', sa.String(), nullable=True),
  23. sa.Column('description', sa.String(length=512), nullable=True),
  24. sa.Column('from_date_time', sa.DateTime(), nullable=True),
  25. sa.Column('until_date_time', sa.DateTime(), nullable=True),
  26. sa.PrimaryKeyConstraint('id', name=op.f('pk_party'))
  27. )
  28. op.create_table('player',
  29. sa.Column('id', sa.Integer(), nullable=False),
  30. sa.Column('name', sa.String(), nullable=True),
  31. sa.Column('nation', sa.String(), nullable=True),
  32. sa.PrimaryKeyConstraint('id', name=op.f('pk_player'))
  33. )
  34. op.create_table('department_stat',
  35. sa.Column('id', sa.Integer(), nullable=False),
  36. sa.Column('date_time', sa.DateTime(), nullable=True),
  37. sa.Column('points', sa.SmallInteger(), nullable=True),
  38. sa.Column('player_id', sa.Integer(), nullable=True),
  39. sa.Column('department_id', sa.Integer(), nullable=True),
  40. sa.ForeignKeyConstraint(['department_id'], ['department.id'], name=op.f('fk_department_stat_department_id_department')),
  41. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_department_stat_player_id_player')),
  42. sa.PrimaryKeyConstraint('id', name=op.f('pk_department_stat'))
  43. )
  44. op.create_table('election',
  45. sa.Column('id', sa.Integer(), nullable=False),
  46. sa.Column('state_id', sa.Integer(), nullable=True),
  47. sa.Column('convocation_date_time', sa.DateTime(), nullable=True),
  48. sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_election_state_id_state')),
  49. sa.PrimaryKeyConstraint('id', name=op.f('pk_election'))
  50. )
  51. op.create_table('player_location',
  52. sa.Column('player_id', sa.Integer(), nullable=True),
  53. sa.Column('region_id', sa.Integer(), nullable=True),
  54. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_player_location_player_id_player')),
  55. sa.ForeignKeyConstraint(['region_id'], ['region.id'], name=op.f('fk_player_location_region_id_region'))
  56. )
  57. op.create_table('player_party',
  58. sa.Column('player_id', sa.Integer(), nullable=True),
  59. sa.Column('party_id', sa.Integer(), nullable=True),
  60. sa.ForeignKeyConstraint(['party_id'], ['party.id'], name=op.f('fk_player_party_party_id_party')),
  61. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_player_party_player_id_player'))
  62. )
  63. op.create_table('player_residency',
  64. sa.Column('player_id', sa.Integer(), nullable=True),
  65. sa.Column('region_id', sa.Integer(), nullable=True),
  66. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_player_residency_player_id_player')),
  67. sa.ForeignKeyConstraint(['region_id'], ['region.id'], name=op.f('fk_player_residency_region_id_region'))
  68. )
  69. op.create_table('state_region',
  70. sa.Column('state_id', sa.Integer(), nullable=True),
  71. sa.Column('region_id', sa.Integer(), nullable=True),
  72. sa.ForeignKeyConstraint(['region_id'], ['region.id'], name=op.f('fk_state_region_region_id_region')),
  73. sa.ForeignKeyConstraint(['state_id'], ['state.id'], name=op.f('fk_state_region_state_id_state'))
  74. )
  75. op.create_table('election_stat',
  76. sa.Column('id', sa.Integer(), nullable=False),
  77. sa.Column('percentage', sa.SmallInteger(), nullable=True),
  78. sa.Column('seats', sa.SmallInteger(), nullable=True),
  79. sa.Column('election_id', sa.Integer(), nullable=True),
  80. sa.ForeignKeyConstraint(['election_id'], ['election.id'], name=op.f('fk_election_stat_election_id_election')),
  81. sa.PrimaryKeyConstraint('id', name=op.f('pk_election_stat'))
  82. )
  83. def downgrade():
  84. op.drop_table('election_stat')
  85. op.drop_table('state_region')
  86. op.drop_table('player_residency')
  87. op.drop_table('player_party')
  88. op.drop_table('player_location')
  89. op.drop_table('election')
  90. op.drop_table('department_stat')
  91. op.drop_table('player')
  92. op.drop_table('party')
  93. op.drop_table('department')