Advertisement
Guest User

Untitled

a guest
May 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. marek@debian9:~/dbs_restruct$ cat import.sh
  2. #!/bin/bash
  3.  
  4. username="supertajne_meno"
  5. password="supertajne_heslo"
  6. host="fixer-srv1"
  7. mysql -u $username -p$password fixer_live -h $host < 0_import.sql
  8.  
  9. marek@debian9:~/dbs_restruct$ cat 0_import.sql
  10. use fixer_live;
  11.  
  12. set sql_safe_updates=0;
  13.  
  14. -- create temporary column for convertion
  15. alter table log_marker_positions add tmp BIGINT not null;
  16. alter table log_board_positions add tmp BIGINT not null;
  17. alter table log_ewma_positions add tmp BIGINT not null;
  18.  
  19. -- make conversion
  20. update log_marker_positions set tmp = unix_timestamp(created) * 1000;
  21. update log_board_positions set tmp = unix_timestamp(created) * 1000;
  22. update log_ewma_positions set tmp = unix_timestamp(created) * 1000;
  23.  
  24. -- modify created column type
  25. alter table log_marker_positions modify created BIGINT not null;
  26. alter table log_board_positions modify created BIGINT not null;
  27. alter table log_ewma_positions modify created BIGINT not null;
  28.  
  29. -- update created column with correct value
  30. update log_marker_positions set created = tmp;
  31. update log_board_positions set created = tmp;
  32. update log_ewma_positions set created = tmp;
  33.  
  34. -- remove temporary column
  35. alter table log_marker_positions drop column tmp;
  36. alter table log_board_positions drop column tmp;
  37. alter table log_ewma_positions drop column tmp;
  38.  
  39. marek@debian9:~/dbs_restruct$ ./import.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement