Changeset 1255


Ignore:
Timestamp:
Dec 9, 2010, 5:49:30 PM (6 years ago)
Author:
work@…
Message:
  • fixed an issue with the automated database upgrade where the idx's needed to be updated (idx=idx-1 where idx>X) which resulted in 'null' objects in template lists... Database upgrade should now perform properly in other environments.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/DatabaseUpgrade.groovy

    r1251 r1255  
    5656                                sql.execute("DELETE FROM study_template_text_fields WHERE template_text_fields_idx='Description'")
    5757
    58                                 // delete all template_template_field references
    59                                 sql.execute("DELETE FROM template_template_field WHERE template_field_id=${id}")
     58                                // find all template id's where this field is used
     59                                sql.eachRow("SELECT DISTINCT template_fields_id, fields_idx FROM template_template_field WHERE template_field_id=${id}") { row ->
     60                                        // delete the template_template_field reference
     61                                        sql.execute("DELETE FROM template_template_field WHERE template_field_id=${id} AND template_fields_id=${row.template_fields_id}")
     62
     63                                        // and lower the idx-es of the remaining fields
     64                                        sql.execute("UPDATE template_template_field SET fields_idx=fields_idx-1 WHERE fields_idx>${row.fields_idx} AND template_fields_id=${row.template_fields_id}")
     65                                }
    6066
    6167                                // and delete the obsolete template field
Note: See TracChangeset for help on using the changeset viewer.