Browse Source

Fix mysql migration

Peter Justin 7 years ago
parent
commit
44ea4c7eb1
2 changed files with 12 additions and 7 deletions
  1. 6 4
      docs/installation.rst
  2. 6 3
      migrations/201802021027_af3f5579c84d_add_cascades.py

+ 6 - 4
docs/installation.rst

@@ -244,12 +244,14 @@ Installation
 ------------
 
 **MySQL users:** Make sure that you create the database using the
-``utf8mb4`` charset::
+``utf8`` charset::
 
-    CREATE DATABASE flaskbb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+    CREATE DATABASE flaskbb CHARACTER SET utf8;
 
-See `this <https://dba.stackexchange.com/a/152383>`_ SO answer for more
-information.
+Even though the ``utf8mb4`` charset is prefered today
+(see `this <https://dba.stackexchange.com/a/152383>`_ SO answer), we have to
+create our database using the ``utf8`` charset. A good explanation about this
+issue can be found `here <https://stackoverflow.com/a/31474509>`_.
 
 For a guided install, run::
 

+ 6 - 3
migrations/201802021027_af3f5579c84d_add_cascades.py

@@ -34,8 +34,9 @@ def upgrade():
         if con.engine.dialect.name == "mysql":
             # user_id
             batch_op.drop_constraint("conversations_ibfk_3", type_='foreignkey')
-            # TODO: setup mysqldb and check
+            # to_user_id
             batch_op.drop_constraint("conversations_ibfk_2", type_='foreignkey')
+            # from_user_id
             batch_op.drop_constraint("conversations_ibfk_1", type_='foreignkey')
         elif con.engine.dialect.name == "postgresql":
             batch_op.drop_constraint('conversations_to_user_id_fkey', type_='foreignkey')
@@ -98,6 +99,10 @@ def upgrade():
         batch_op.create_foreign_key(batch_op.f('fk_groups_users_group_id_groups'), 'groups', ['group_id'], ['id'], ondelete='CASCADE')
 
     with op.batch_alter_table('messages', schema=None) as batch_op:
+        batch_op.alter_column('user_id',
+               existing_type=sa.INTEGER(),
+               nullable=True)
+
         if con.engine.dialect.name == "mysql":
             # conversation_id
             batch_op.drop_constraint("messages_ibfk_1", type_='foreignkey')
@@ -107,8 +112,6 @@ def upgrade():
             batch_op.drop_constraint('messages_conversation_id_fkey', type_='foreignkey')
             batch_op.drop_constraint('messages_user_id_fkey', type_='foreignkey')
 
-        batch_op.alter_column('user_id', existing_type=flaskbb.utils.database.UTCDateTime(timezone=True), nullable=True)
-
         batch_op.create_foreign_key(batch_op.f('fk_messages_conversation_id_conversations'), 'conversations', ['conversation_id'], ['id'], ondelete='CASCADE')
         batch_op.create_foreign_key(batch_op.f('fk_messages_user_id_users'), 'users', ['user_id'], ['id'], ondelete='SET NULL')