Changeset 1776
- Timestamp:
- Apr 19, 2011, 4:35:56 PM (12 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/DatabaseUpgrade.groovy
r1689 r1776 38 38 fixDateCreatedAndLastUpdated(sql, db) 39 39 dropAssayModulePlatform(sql, db) // r1689 40 makeStudyTitleUnique(sql, db) // #401 40 41 } 41 42 … … 306 307 } 307 308 } 309 310 /** 311 * Make sure the study title is unique 312 * @param sql 313 * @param db 314 */ 315 public static void makeStudyTitleUnique(sql, db) { 316 def titleCount,title,newTitle 317 318 // are we running postgreSQL? 319 if (db == "org.postgresql.Driver") { 320 // yes, find all duplicate study titles 321 sql.eachRow("SELECT DISTINCT a.title FROM Study a WHERE (SELECT count(*) FROM Study b WHERE b.title=a.title) > 1") { row -> 322 // grom what we are doing 323 if (String.metaClass.getMetaMethod("grom")) "making study title '${row.title}' unique".grom() 324 325 // iterate through studies that use this duplicate title 326 titleCount = 1 327 title = row.title.replace("'","\'") 328 sql.eachRow(sprintf("SELECT id FROM Study WHERE title='%s'", title)) { studyRow -> 329 newTitle = "${title} - ${titleCount}" 330 sql.execute(sprintf("UPDATE Study SET title='%s' WHERE id=%d",newTitle,studyRow.id)) 331 titleCount++ 332 } 333 } 334 } 335 } 308 336 } -
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r1775 r1776 52 52 53 53 static constraints = { 54 title(nullable:false, blank: false, maxSize: 255)54 title(nullable:false, blank: false, unique:true, maxSize: 255) 55 55 owner(nullable: true, blank: true) 56 56 code(nullable: true, blank: true, unique: true, maxSize: 255)
Note: See TracChangeset
for help on using the changeset viewer.