201705041144_933bd7d807c4_add_more_non_nullables.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. op.execute('SET FOREIGN_KEY_CHECKS=0;')
  28. with op.batch_alter_table('groups_users', schema=None) as batch_op:
  29. batch_op.alter_column('group_id',
  30. existing_type=sa.INTEGER(),
  31. nullable=False)
  32. batch_op.alter_column('user_id',
  33. existing_type=sa.INTEGER(),
  34. nullable=False)
  35. # activate them again
  36. if connection.engine.dialect.name == "mysql":
  37. op.execute('SET FOREIGN_KEY_CHECKS=1;')
  38. with op.batch_alter_table('messages', 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('posts', schema=None) as batch_op:
  43. batch_op.alter_column('date_created',
  44. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  45. nullable=False)
  46. with op.batch_alter_table('reports', schema=None) as batch_op:
  47. batch_op.alter_column('post_id',
  48. existing_type=sa.INTEGER(),
  49. nullable=True)
  50. batch_op.alter_column('reported',
  51. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  52. nullable=False)
  53. batch_op.alter_column('reporter_id',
  54. existing_type=sa.INTEGER(),
  55. nullable=True)
  56. with op.batch_alter_table('topics', schema=None) as batch_op:
  57. batch_op.alter_column('date_created',
  58. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  59. nullable=False)
  60. batch_op.alter_column('important',
  61. existing_type=sa.BOOLEAN(),
  62. nullable=False)
  63. batch_op.alter_column('last_updated',
  64. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  65. nullable=False)
  66. batch_op.alter_column('locked',
  67. existing_type=sa.BOOLEAN(),
  68. nullable=False)
  69. batch_op.alter_column('post_count',
  70. existing_type=sa.INTEGER(),
  71. nullable=False)
  72. batch_op.alter_column('views',
  73. existing_type=sa.INTEGER(),
  74. nullable=False)
  75. with op.batch_alter_table('topicsread', schema=None) as batch_op:
  76. batch_op.alter_column('last_read',
  77. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  78. nullable=False)
  79. with op.batch_alter_table('users', schema=None) as batch_op:
  80. batch_op.alter_column('activated',
  81. existing_type=sa.BOOLEAN(),
  82. nullable=False)
  83. batch_op.alter_column('date_joined',
  84. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  85. nullable=False)
  86. batch_op.alter_column('login_attempts',
  87. existing_type=sa.INTEGER(),
  88. nullable=False)
  89. # ### end Alembic commands ###
  90. def downgrade():
  91. connection = op.get_bind()
  92. # ### commands auto generated by Alembic - please adjust! ###
  93. with op.batch_alter_table('users', schema=None) as batch_op:
  94. batch_op.alter_column('login_attempts',
  95. existing_type=sa.INTEGER(),
  96. nullable=True)
  97. batch_op.alter_column('date_joined',
  98. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  99. nullable=True)
  100. batch_op.alter_column('activated',
  101. existing_type=sa.BOOLEAN(),
  102. nullable=True)
  103. with op.batch_alter_table('topicsread', schema=None) as batch_op:
  104. batch_op.alter_column('last_read',
  105. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  106. nullable=True)
  107. with op.batch_alter_table('topics', schema=None) as batch_op:
  108. batch_op.alter_column('views',
  109. existing_type=sa.INTEGER(),
  110. nullable=True)
  111. batch_op.alter_column('post_count',
  112. existing_type=sa.INTEGER(),
  113. nullable=True)
  114. batch_op.alter_column('locked',
  115. existing_type=sa.BOOLEAN(),
  116. nullable=True)
  117. batch_op.alter_column('last_updated',
  118. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  119. nullable=True)
  120. batch_op.alter_column('important',
  121. existing_type=sa.BOOLEAN(),
  122. nullable=True)
  123. batch_op.alter_column('date_created',
  124. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  125. nullable=True)
  126. with op.batch_alter_table('reports', schema=None) as batch_op:
  127. batch_op.alter_column('reporter_id',
  128. existing_type=sa.INTEGER(),
  129. nullable=False)
  130. batch_op.alter_column('reported',
  131. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  132. nullable=True)
  133. batch_op.alter_column('post_id',
  134. existing_type=sa.INTEGER(),
  135. nullable=False)
  136. with op.batch_alter_table('posts', 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. with op.batch_alter_table('messages', schema=None) as batch_op:
  141. batch_op.alter_column('date_created',
  142. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  143. nullable=True)
  144. if connection.engine.dialect.name == "mysql":
  145. op.execute('SET FOREIGN_KEY_CHECKS=0;')
  146. with op.batch_alter_table('groups_users', schema=None) as batch_op:
  147. batch_op.alter_column('user_id',
  148. existing_type=sa.INTEGER(),
  149. nullable=True)
  150. batch_op.alter_column('group_id',
  151. existing_type=sa.INTEGER(),
  152. nullable=True)
  153. if connection.engine.dialect.name == "mysql":
  154. op.execute('SET FOREIGN_KEY_CHECKS=1;')
  155. with op.batch_alter_table('forumsread', schema=None) as batch_op:
  156. batch_op.alter_column('last_read',
  157. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  158. nullable=True)
  159. with op.batch_alter_table('conversations', schema=None) as batch_op:
  160. batch_op.alter_column('date_created',
  161. existing_type=flaskbb.utils.database.UTCDateTime(timezone=True),
  162. nullable=True)
  163. # ### end Alembic commands ###