← Back to team overview

openerp-community team mailing list archive

lp:~savoirfairelinux-openerp/openerp-mgmtsystem/6.1-fix-1108215 into lp:~openerp-community/openerp-mgmtsystem/nc-extend

 

Virgil Dupras has proposed merging lp:~savoirfairelinux-openerp/openerp-mgmtsystem/6.1-fix-1108215 into lp:~openerp-community/openerp-mgmtsystem/nc-extend.

Requested reviews:
  Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903)
Related bugs:
  Bug #1108215 in OpenERP Management System: "[6.1] ProgrammingError: column mgmtsystem_audit_nonconformity_rel.mgmtsystem_nonconformity_id does not exist LINE 1: SELECT mgmtsystem_audit_nonconformity_rel.mgmtsystem_nonconf..."
  https://bugs.launchpad.net/openerp-mgmtsystem/+bug/1108215

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-mgmtsystem/6.1-fix-1108215/+merge/145409
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-mgmtsystem/6.1-fix-1108215/+merge/145409
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openerp-mgmtsystem/nc-extend.
=== modified file 'mgmtsystem_audit/migrations/6.1.1.0/post-migration.py'
--- mgmtsystem_audit/migrations/6.1.1.0/post-migration.py	2013-01-25 13:56:44 +0000
+++ mgmtsystem_audit/migrations/6.1.1.0/post-migration.py	2013-01-29 15:42:35 +0000
@@ -19,8 +19,6 @@
 #
 ##############################################################################
 
-import os
-from osv import osv
 import logging
 
 logger = logging.getLogger('upgrade')
@@ -32,4 +30,21 @@
     cr.execute("update mgmtsystem_audit set state = 'open' where state = 'o'")
     cr.execute("update mgmtsystem_audit set state = 'done' where state = 'c'")
 
+    logger.info("Renaming relation columns")
+    # Our model's relation to nonconformity was previously wrongly defined as:
+    # 'nonconformity_ids': fields.many2many('mgmtsystem.nonconformity','mgmtsystem_audit_nonconformity_rel','mgmtsystem_action_id','mgmtsystem_audit_id','Nonconformities')
+    # In v1.0, it's been fixed to:
+    # 'nonconformity_ids': fields.many2many('mgmtsystem.nonconformity','mgmtsystem_audit_nonconformity_rel','mgmtsystem_audit_id','mgmtsystem_nonconformity_id','Nonconformities')
+    # However, OpenERP doesn't seem to automatically handle column renames here. We have to do it manually.
+
+    # Now, verify if we actually have the old schema.
+    cr.execute("select * from mgmtsystem_audit_nonconformity_rel limit 0")
+    colnames = set(desc[0] for desc in cr.description)
+    if "mgmtsystem_action_id" in colnames:
+        # It's ok, we can proceed with the renames.
+        cr.execute("alter table mgmtsystem_audit_nonconformity_rel rename column mgmtsystem_audit_id to mgmtsystem_nonconformity_id")
+        cr.execute("alter table mgmtsystem_audit_nonconformity_rel rename column mgmtsystem_action_id to mgmtsystem_audit_id")
+    else:
+        logging.warning("mgmtsystem_audit_nonconformity_rel already migrated. Skipping.")
+
     logger.info("mgmtsystem_audit update... done!")


Follow ups