c98e920c06ae_add_ballots_remove_page_file_relation.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """add_ballots_remove_page_file_relation
  2. Revision ID: c98e920c06ae
  3. Revises: d692d6e1a31d
  4. Create Date: 2019-03-29 17:49:34.434786
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = 'c98e920c06ae'
  10. down_revision = 'd692d6e1a31d'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. op.create_table('priority',
  15. sa.Column('id', sa.Integer(), nullable=False),
  16. sa.Column('name', sa.String(), nullable=False),
  17. sa.Column('description', sa.String(), nullable=False),
  18. sa.PrimaryKeyConstraint('id', name=op.f('pk_priority'))
  19. )
  20. op.create_table('ballot',
  21. sa.Column('id', sa.Integer(), nullable=False),
  22. sa.Column('name', sa.String(), nullable=False),
  23. sa.Column('description', sa.String(), nullable=True),
  24. sa.Column('start_at', sa.DateTime(), nullable=True),
  25. sa.Column('end_at', sa.DateTime(), nullable=False),
  26. sa.Column('user_id', sa.Integer(), nullable=True),
  27. sa.Column('priority_id', sa.Integer(), nullable=True),
  28. sa.ForeignKeyConstraint(['priority_id'], ['priority.id'], name=op.f('fk_ballot_priority_id_priority')),
  29. sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_ballot_user_id_user')),
  30. sa.PrimaryKeyConstraint('id', name=op.f('pk_ballot'))
  31. )
  32. op.create_table('question',
  33. sa.Column('id', sa.Integer(), nullable=False),
  34. sa.Column('name', sa.String(), nullable=False),
  35. sa.Column('description', sa.String(), nullable=True),
  36. sa.Column('ballot_id', sa.Integer(), nullable=True),
  37. sa.ForeignKeyConstraint(['ballot_id'], ['ballot.id'], name=op.f('fk_question_ballot_id_ballot')),
  38. sa.PrimaryKeyConstraint('id', name=op.f('pk_question'))
  39. )
  40. op.create_table('option',
  41. sa.Column('id', sa.Integer(), nullable=False),
  42. sa.Column('motivation', sa.String(), nullable=True),
  43. sa.Column('user_id', sa.Integer(), nullable=True),
  44. sa.Column('question_id', sa.Integer(), nullable=True),
  45. sa.ForeignKeyConstraint(['question_id'], ['question.id'], name=op.f('fk_option_question_id_question')),
  46. sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_option_user_id_user')),
  47. sa.PrimaryKeyConstraint('id', name=op.f('pk_option'))
  48. )
  49. op.create_table('vote',
  50. sa.Column('id', sa.Integer(), nullable=False),
  51. sa.Column('datetime', sa.DateTime(), nullable=True),
  52. sa.Column('option_id', sa.Integer(), nullable=True),
  53. sa.Column('user_id', sa.Integer(), nullable=True),
  54. sa.ForeignKeyConstraint(['option_id'], ['option.id'], name=op.f('fk_vote_option_id_option')),
  55. sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_vote_user_id_user')),
  56. sa.PrimaryKeyConstraint('id', name=op.f('pk_vote'))
  57. )
  58. op.drop_table('page_file')
  59. op.add_column('user', sa.Column('alt', sa.Boolean(), server_default='f', nullable=True))
  60. op.add_column('user', sa.Column('discord', sa.String(length=255), nullable=True))
  61. op.add_column('user', sa.Column('game_id', sa.BigInteger(), nullable=True))
  62. op.add_column('user', sa.Column('party_member', sa.Boolean(), server_default='f', nullable=True))
  63. op.add_column('user', sa.Column('question_id', sa.Integer(), nullable=True))
  64. op.create_unique_constraint(op.f('uq_user_discord'), 'user', ['discord'])
  65. op.create_unique_constraint(op.f('uq_user_email'), 'user', ['email'])
  66. op.create_unique_constraint(op.f('uq_user_game_id'), 'user', ['game_id'])
  67. op.create_unique_constraint(op.f('uq_user_name'), 'user', ['name'])
  68. op.drop_constraint('user_name_key', 'user', type_='unique')
  69. op.create_foreign_key(op.f('fk_user_question_id_question'), 'user', 'question', ['question_id'], ['id'])
  70. def downgrade():
  71. op.drop_constraint(op.f('fk_user_question_id_question'), 'user', type_='foreignkey')
  72. op.create_unique_constraint('user_name_key', 'user', ['name'])
  73. op.drop_constraint(op.f('uq_user_name'), 'user', type_='unique')
  74. op.drop_constraint(op.f('uq_user_game_id'), 'user', type_='unique')
  75. op.drop_constraint(op.f('uq_user_email'), 'user', type_='unique')
  76. op.drop_constraint(op.f('uq_user_discord'), 'user', type_='unique')
  77. op.drop_column('user', 'question_id')
  78. op.drop_column('user', 'party_member')
  79. op.drop_column('user', 'game_id')
  80. op.drop_column('user', 'discord')
  81. op.drop_column('user', 'alt')
  82. op.create_table('page_file',
  83. sa.Column('page_id', sa.INTEGER(), autoincrement=False, nullable=False),
  84. sa.Column('file_id', sa.INTEGER(), autoincrement=False, nullable=False),
  85. sa.ForeignKeyConstraint(['file_id'], ['file.id'], name='page_file_file_id_fkey'),
  86. sa.ForeignKeyConstraint(['page_id'], ['page.id'], name='page_file_page_id_fkey'),
  87. sa.PrimaryKeyConstraint('page_id', 'file_id', name='page_file_pkey')
  88. )
  89. op.drop_table('vote')
  90. op.drop_table('option')
  91. op.drop_table('question')
  92. op.drop_table('ballot')
  93. op.drop_table('priority')