[odrs-web] Fix up the '0000-00-00 00:00:00' review datetime misconfiguration



commit c0e394c6ef59aa1b2c3198b3188694b89f4a64cf
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jun 28 16:24:19 2019 +0100

    Fix up the '0000-00-00 00:00:00' review datetime misconfiguration

 app_data/migrations/versions/b8243269e9cf_.py | 7 +++++++
 app_data/odrs/views_admin.py                  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/app_data/migrations/versions/b8243269e9cf_.py b/app_data/migrations/versions/b8243269e9cf_.py
index 4503876..5eeb4ce 100644
--- a/app_data/migrations/versions/b8243269e9cf_.py
+++ b/app_data/migrations/versions/b8243269e9cf_.py
@@ -14,11 +14,18 @@ from alembic import op
 import sqlalchemy as sa
 from sqlalchemy.dialects import mysql
 
+from odrs import db
+from odrs.models import Review
+
 def upgrade():
     op.alter_column('reviews', 'date_deleted',
                existing_type=mysql.TIMESTAMP(),
                nullable=True,
                existing_server_default=sa.text("'0000-00-00 00:00:00'"))
+    for review in db.session.query(Review).all():
+        if review.date_deleted == '0000-00-00 00:00:00':
+             review.date_deleted = None
+    db.session.commit()
 
 
 def downgrade():
diff --git a/app_data/odrs/views_admin.py b/app_data/odrs/views_admin.py
index d263e6e..b09fe98 100644
--- a/app_data/odrs/views_admin.py
+++ b/app_data/odrs/views_admin.py
@@ -346,7 +346,7 @@ def admin_unremove(review_id):
     if not review:
         flash('No review with that ID')
         return redirect(url_for('.odrs_index'))
-    review.date_deleted = 0
+    review.date_deleted = None
     db.session.commit()
     flash('Review unremoved')
     return redirect(url_for('.admin_show_review', review_id=review_id))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]