Skip to content
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

Merged
merged 2 commits into from
May 2, 2016
Merged

Add indexes to SQL fields (and other changes) #533

merged 2 commits into from
May 2, 2016

Conversation

qligier
Copy link
Contributor

@qligier qligier commented Apr 27, 2016

See #531 and #513 for comments.

@electerious
Copy link
Owner

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.

@electerious electerious merged commit 29ae681 into electerious:develop May 2, 2016
electerious added a commit that referenced this pull request May 2, 2016
electerious added a commit that referenced this pull request May 2, 2016
@electerious
Copy link
Owner

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.

@qligier
Copy link
Contributor Author

qligier commented May 2, 2016

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.
Edit: add index only if the test doesn't return rows

@electerious
Copy link
Owner

Fixed. Thanks!

@electerious electerious mentioned this pull request Jun 12, 2016
hrniels pushed a commit to hrniels/Lychee that referenced this pull request Jul 29, 2016
hrniels pushed a commit to hrniels/Lychee that referenced this pull request Jul 29, 2016
hrniels pushed a commit to hrniels/Lychee that referenced this pull request Jul 29, 2016
hrniels pushed a commit to hrniels/Lychee that referenced this pull request Jul 29, 2016
hrniels pushed a commit to hrniels/Lychee that referenced this pull request Jul 29, 2016
@qligier qligier deleted the pr-sql1 branch September 24, 2016 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants