201705041144_933bd7d807c4_add_more_non_nullables.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. """Add more non nullables
  2. Revision ID: 933bd7d807c4
  3. Revises: d87cea4e995d
  4. Create Date: 2017-05-04 11:44:16.146471
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. import flaskbb
  9. # revision identifiers, used by Alembic.
  10. revision = '933bd7d807c4'
  11. down_revision = 'd87cea4e995d'
  12. branch_labels = ()
  13. depends_on = None
  14. def upgrade():
  15. connection = op.get_bind()
  16. # ### commands auto generated by Alembic - please adjust! ###
  17. with op.batch_alter_table('conversations', schema=None) as batch_op:
  18. batch_op.alter_column('date_created',
  19. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  20. nullable=False)
  21. with op.batch_alter_table('forumsread', schema=None) as batch_op:
  22. batch_op.alter_column('last_read',
  23. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  24. nullable=False)
  25. # See https://github.com/sh4nks/flaskbb/issues/309
  26. if connection.engine.dialect.name != "mysql":
  27. with op.batch_alter_table('groups_users', schema=None) as batch_op:
  28. batch_op.alter_column('group_id',
  29. existing_type=sa.INTEGER(),
  30. nullable=False)
  31. batch_op.alter_column('user_id',
  32. existing_type=sa.INTEGER(),
  33. nullable=False)
  34. with op.batch_alter_table('messages', schema=None) as batch_op:
  35. batch_op.alter_column('date_created',
  36. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  37. nullable=False)
  38. with op.batch_alter_table('posts', schema=None) as batch_op:
  39. batch_op.alter_column('date_created',
  40. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  41. nullable=False)
  42. with op.batch_alter_table('reports', schema=None) as batch_op:
  43. batch_op.alter_column('post_id',
  44. existing_type=sa.INTEGER(),
  45. nullable=True)
  46. batch_op.alter_column('reported',
  47. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  48. nullable=False)
  49. batch_op.alter_column('reporter_id',
  50. existing_type=sa.INTEGER(),
  51. nullable=True)
  52. with op.batch_alter_table('topics', schema=None) as batch_op:
  53. batch_op.alter_column('date_created',
  54. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  55. nullable=False)
  56. batch_op.alter_column('important',
  57. existing_type=sa.BOOLEAN(),
  58. nullable=False)
  59. batch_op.alter_column('last_updated',
  60. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  61. nullable=False)
  62. batch_op.alter_column('locked',
  63. existing_type=sa.BOOLEAN(),
  64. nullable=False)
  65. batch_op.alter_column('post_count',
  66. existing_type=sa.INTEGER(),
  67. nullable=False)
  68. batch_op.alter_column('views',
  69. existing_type=sa.INTEGER(),
  70. nullable=False)
  71. with op.batch_alter_table('topicsread', schema=None) as batch_op:
  72. batch_op.alter_column('last_read',
  73. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  74. nullable=False)
  75. with op.batch_alter_table('users', schema=None) as batch_op:
  76. batch_op.alter_column('activated',
  77. existing_type=sa.BOOLEAN(),
  78. nullable=False)
  79. batch_op.alter_column('date_joined',
  80. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  81. nullable=False)
  82. batch_op.alter_column('login_attempts',
  83. existing_type=sa.INTEGER(),
  84. nullable=False)
  85. # ### end Alembic commands ###
  86. def downgrade():
  87. connection = op.get_bind()
  88. # ### commands auto generated by Alembic - please adjust! ###
  89. with op.batch_alter_table('users', schema=None) as batch_op:
  90. batch_op.alter_column('login_attempts',
  91. existing_type=sa.INTEGER(),
  92. nullable=True)
  93. batch_op.alter_column('date_joined',
  94. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  95. nullable=True)
  96. batch_op.alter_column('activated',
  97. existing_type=sa.BOOLEAN(),
  98. nullable=True)
  99. with op.batch_alter_table('topicsread', schema=None) as batch_op:
  100. batch_op.alter_column('last_read',
  101. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  102. nullable=True)
  103. with op.batch_alter_table('topics', schema=None) as batch_op:
  104. batch_op.alter_column('views',
  105. existing_type=sa.INTEGER(),
  106. nullable=True)
  107. batch_op.alter_column('post_count',
  108. existing_type=sa.INTEGER(),
  109. nullable=True)
  110. batch_op.alter_column('locked',
  111. existing_type=sa.BOOLEAN(),
  112. nullable=True)
  113. batch_op.alter_column('last_updated',
  114. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  115. nullable=True)
  116. batch_op.alter_column('important',
  117. existing_type=sa.BOOLEAN(),
  118. nullable=True)
  119. batch_op.alter_column('date_created',
  120. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  121. nullable=True)
  122. with op.batch_alter_table('reports', schema=None) as batch_op:
  123. batch_op.alter_column('reporter_id',
  124. existing_type=sa.INTEGER(),
  125. nullable=False)
  126. batch_op.alter_column('reported',
  127. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  128. nullable=True)
  129. batch_op.alter_column('post_id',
  130. existing_type=sa.INTEGER(),
  131. nullable=False)
  132. with op.batch_alter_table('posts', schema=None) as batch_op:
  133. batch_op.alter_column('date_created',
  134. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  135. nullable=True)
  136. with op.batch_alter_table('messages', schema=None) as batch_op:
  137. batch_op.alter_column('date_created',
  138. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  139. nullable=True)
  140. if connection.engine.dialect.name != "mysql":
  141. with op.batch_alter_table('groups_users', schema=None) as batch_op:
  142. batch_op.alter_column('user_id',
  143. existing_type=sa.INTEGER(),
  144. nullable=True)
  145. batch_op.alter_column('group_id',
  146. existing_type=sa.INTEGER(),
  147. nullable=True)
  148. with op.batch_alter_table('forumsread', schema=None) as batch_op:
  149. batch_op.alter_column('last_read',
  150. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  151. nullable=True)
  152. with op.batch_alter_table('conversations', schema=None) as batch_op:
  153. batch_op.alter_column('date_created',
  154. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  155. nullable=True)
  156. # ### end Alembic commands ###