Advertisement
matthewpoer

SugarCRM: Convert Text field to Date

May 24th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.21 KB | None | 0 0
  1. -- add tmp field for safety
  2. alter table contacts_cstm add temp_rfc_rcd_c varchar(255);
  3. -- update tmp field data. Should be around
  4. update contacts_cstm set temp_rfc_rcd_c = rfc_rcd_c;
  5. -- count... ~1192
  6. select count(*) from contacts_cstm where temp_rfc_rcd_c is not null and temp_rfc_rcd_c <> '';
  7. -- make the change
  8. alter table contacts_cstm modify rfc_rcd_c date;
  9. -- cleanup... because 0000-00-00  is useless
  10. update contacts_cstm set rfc_rcd_c = null where rfc_rcd_c = '0000-00-00';
  11. -- compare data integrity post- datatype change. ~1192 again?
  12. select count(*) from contacts_cstm where rfc_rcd_c is not null and rfc_rcd_c <> '';
  13.  
  14.  
  15. -- escape plan, if data integrity didn't hold well (3%)
  16. alter table contacts_cstm modify rfc_rcd_c varchar(255);
  17. update contacts_cstm set rfc_rcd_c = temp_rfc_rcd_c;
  18.  
  19. -- If < 3% of data loss, or if it's perfect
  20. update fields_meta_data set
  21. type='date',len=null,date_modified=NOW()
  22.  where id = 'Contactsrfc_rcd_c';
  23.  
  24. -- moving forward with some data loss, 0-3%, please send me a backup file
  25. -- with the temp_rfc_rcd_c column still in the table. I'll manually fix.
  26.  
  27. -- if counts match exactly, go ahead and drop temp_rfc_rcd_c
  28. alter table contacts_cstm drop column temp_rfc_rcd_c;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement