-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add indexes to SQL fields (and other changes) #533
Conversation
Thanks! Will try to publish v3.1.1 this weekend and merge the PR after the release. Just one thing: The default table structure (https://github.com/electerious/Lychee/blob/master/php/database/photos_table.sql and https://github.com/electerious/Lychee/blob/master/php/database/albums_table.sql) should be adjusted, too. |
It says "Could not add index to the album id field!" and outputs "Duplicate key name 'Index_album'" in the log. Update scripts should work no matter how often they get executed. I guess that's the problem. |
Right, let's add a test for the indexes: // Add index to the album id field
$check = Database::execute($connection, Database::prepare($connection, "SHOW INDEX FROM ? WHERE KEY_NAME = 'Index_album'", [LYCHEE_TABLE_PHOTOS]), 'update_030102', __LINE__);
if ($check->num_rows == 0) {
$query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_album` (`album`)", [LYCHEE_TABLE_PHOTOS]);
$result = Database::execute($connection, $query, 'update_030102', __LINE__);
if ($result===false) Response::error('Could not add index to the album id field!');
}
// Add index to the star field
$check = Database::execute($connection, Database::prepare($connection, "SHOW INDEX FROM ? WHERE KEY_NAME = 'Index_star'", [LYCHEE_TABLE_PHOTOS]), 'update_030102', __LINE__);
if ($check->num_rows == 0) {
$query = Database::prepare($connection, "ALTER TABLE `?` ADD INDEX `Index_star` (`star`)", [LYCHEE_TABLE_PHOTOS]);
$result = Database::execute($connection, $query, 'update_030102', __LINE__);
if ($result===false) Response::error('Could not add index to the star field!');
} I don't have time to test it yet nor to create the PR, sorry. |
Fixed. Thanks! |
See #531 and #513 for comments.