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

SchemaHandler - Cleanup string handling and fix syntax error #26275

Merged
merged 1 commit into from
May 19, 2023

Conversation

colemanw
Copy link
Member

Overview

Note: This is a small piece of #25871 which was in there to fix a test failure but feels like it belongs in its own PR for easier review.

The SchemaHandler is a utility which takes an array of table properties and outputs a CREATE/ALTER TABLE SQL string. It contained a bug which wrote invalid sql when creating a table with indexes, and while I was in there I cleaned up some function signatures to clarify they they all output strings.

Before

I guess no one had ever tried to make use of this particular functionality before, but it was definitely broken. When creating a table with indexes it would write SQL like:

CREATE TABLE `foo`
...
INDEX_bar ( bar ),
INDEX_baz ( baz );

This causes a fatal error in sql because you can't declare indexes without the INDEX keyword.

After

CREATE TABLE `foo`
...
INDEX INDEX_bar ( bar ),
INDEX INDEX_baz ( baz );

@civibot
Copy link

civibot bot commented May 19, 2023

(Standard links)

@civibot civibot bot added the master label May 19, 2023
}
foreach ($params['fields'] as $field) {
$sql .= self::buildSearchIndexSQL($field, $separator);
$sql .= self::buildSearchIndexSQL($field, $separator, 'INDEX ');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line fixes the bug. The rest is just code cleanup.

@totten
Copy link
Member

totten commented May 19, 2023

Code-cleanups look sensible. This usage of buildSearchIndexSQL() looks more consistent with the other usage(s) of buildSearchIndexSQL().

I couldn't find an existing/organic way to r-run. The bug specifically affects creating a new table with new fields+indexes (at the same time). The existing/organic workflows do those as separate steps, which is why we never noticed. (FWIW, they seem fine before+after the patch.)

Sounds like there's implicit coverage by way of 25871.

Merging.

@totten totten merged commit c2ffc99 into civicrm:master May 19, 2023
@colemanw colemanw deleted the fixSchemaHandler branch May 20, 2023 00:55
@colemanw
Copy link
Member Author

Thanks @totten - yes there is test cover in #25871

@colemanw
Copy link
Member Author

@totten I just found 2 more oddities in that class: #26282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants