update_030102.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Update to version 3.1.2
  4. */
  5. use Lychee\Modules\Database;
  6. use Lychee\Modules\Response;
  7. // Change type of the album id field
  8. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `album` `album` BIGINT UNSIGNED NOT NULL", array(LYCHEE_TABLE_PHOTOS));
  9. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  10. if ($result===false) Response::error('Could not change type of the album id field!');
  11. // Add index to the album id field
  12. $query = Database::prepare($connection, "SHOW INDEX FROM `?` WHERE KEY_NAME = 'Index_album'", array(LYCHEE_TABLE_PHOTOS));
  13. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  14. if ($result===false) Response::error('Could not check if Index_album exists!');
  15. if ($result->num_rows===0) {
  16. $query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_album` (`album`)", array(LYCHEE_TABLE_PHOTOS));
  17. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  18. if ($result===false) Response::error('Could not add index to the album id field!');
  19. }
  20. // Add index to the star field
  21. $query = Database::prepare($connection, "SHOW INDEX FROM `?` WHERE KEY_NAME = 'Index_star'", array(LYCHEE_TABLE_PHOTOS));
  22. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  23. if ($result===false) Response::error('Could not check if Index_star exists!');
  24. if ($result->num_rows===0) {
  25. $query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_star` (`star`)", array(LYCHEE_TABLE_PHOTOS));
  26. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  27. if ($result===false) Response::error('Could not add index to the star field!');
  28. }
  29. // Change type of the checksum field
  30. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `checksum` `checksum` CHAR(40) NULL DEFAULT NULL", array(LYCHEE_TABLE_PHOTOS));
  31. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  32. if ($result===false) Response::error('Could not change type of the checksum field!');
  33. // Change type of the thumbUrl field
  34. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `thumbUrl` `thumbUrl` CHAR(37) NOT NULL", array(LYCHEE_TABLE_PHOTOS));
  35. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  36. if ($result===false) Response::error('Could not change type of the thumbUrl field!');
  37. // Change type of the id field
  38. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `id` `id` BIGINT(14) UNSIGNED NOT NULL", array(LYCHEE_TABLE_PHOTOS));
  39. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  40. if ($result===false) Response::error('Could not change type of the id field!');
  41. // Change type of the id field
  42. $query = Database::prepare($connection, "ALTER TABLE `?` CHANGE `id` `id` BIGINT(14) UNSIGNED NOT NULL", array(LYCHEE_TABLE_ALBUMS));
  43. $result = Database::execute($connection, $query, 'update_030102', __LINE__);
  44. if ($result===false) Response::error('Could not change type of the id field!');
  45. // Set version
  46. //if (Database::setVersion($connection, '030102')===false) Response::error('Could not update version of database!');
  47. ?>