75b3282b1d3f_add_telegram_account.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """add_telegram_account
  2. Revision ID: 75b3282b1d3f
  3. Revises: 661865b159c9
  4. Create Date: 2020-01-26 15:17:12.904010
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = '75b3282b1d3f'
  10. down_revision = '661865b159c9'
  11. branch_labels = None
  12. depends_on = None
  13. def upgrade():
  14. op.create_table('telegram_account',
  15. sa.Column('id', sa.BigInteger(), nullable=False),
  16. sa.Column('name', sa.String(), nullable=True),
  17. sa.Column('registration_date', sa.DateTime(), nullable=True),
  18. sa.PrimaryKeyConstraint('id', name=op.f('pk_telegram_account'))
  19. )
  20. op.create_table('player_telegram',
  21. sa.Column('player_id', sa.BigInteger(), nullable=False),
  22. sa.Column('telegram_id', sa.BigInteger(), nullable=False),
  23. sa.Column('from_date_time', sa.DateTime(), nullable=False),
  24. sa.Column('until_date_time', sa.DateTime(), nullable=True),
  25. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_player_telegram_player_id_player')),
  26. sa.ForeignKeyConstraint(['telegram_id'], ['telegram_account.id'], name=op.f('fk_player_telegram_telegram_id_telegram_account')),
  27. sa.PrimaryKeyConstraint('player_id', 'telegram_id', 'from_date_time', name=op.f('pk_player_telegram'))
  28. )
  29. op.create_table('telegram_handle',
  30. sa.Column('id', sa.Integer(), nullable=False),
  31. sa.Column('handle', sa.String(), nullable=True),
  32. sa.Column('registration_date', sa.DateTime(), nullable=True),
  33. sa.Column('telegram_account_id', sa.BigInteger(), nullable=True),
  34. sa.ForeignKeyConstraint(['telegram_account_id'], ['telegram_account.id'], name=op.f('fk_telegram_handle_telegram_account_id_telegram_account')),
  35. sa.PrimaryKeyConstraint('id', name=op.f('pk_telegram_handle'))
  36. )
  37. op.create_table('telegram_verification',
  38. sa.Column('player_id', sa.BigInteger(), nullable=False),
  39. sa.Column('telegram_id', sa.BigInteger(), nullable=False),
  40. sa.Column('code', sa.String(), nullable=True),
  41. sa.Column('date_time', sa.DateTime(), nullable=True),
  42. sa.Column('confirmed', sa.Boolean(), server_default='f', nullable=True),
  43. sa.ForeignKeyConstraint(['player_id'], ['player.id'], name=op.f('fk_telegram_verification_player_id_player')),
  44. sa.ForeignKeyConstraint(['telegram_id'], ['telegram_account.id'], name=op.f('fk_telegram_verification_telegram_id_telegram_account')),
  45. sa.PrimaryKeyConstraint('player_id', 'telegram_id', name=op.f('pk_telegram_verification'))
  46. )
  47. def downgrade():
  48. op.drop_table('telegram_verification')
  49. op.drop_table('telegram_handle')
  50. op.drop_table('player_telegram')
  51. op.drop_table('telegram_account')