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

CRM: 3406 - address SQLite table creation error #34872

Conversation

tbradsha
Copy link
Contributor

@tbradsha tbradsha commented Jan 5, 2024

Resolves Automattic/zero-bs-crm#3406 - address SQLite table creation error

Proposed changes:

If using SQLite, the System Status page (/wp-admin/admin.php?page=zerobscrm-systemstatus&tab=status) will show a notice that there were issues creating database tables.

This addresses the above by short-circuiting the InnoDB check if using SQLite, as we already know SQLite has no InnoDB support and the SHOW ENGINES query used is not valid in SQLite.

This was a bit complicated, as it was supposed to output the errors but they were always blank. Digging around, I learned that if a database query was determined to be invalid prior to running, it just returns false rather than actually running and providing the error. In this case, it seems it was because SHOW ENGINES was not deemed valid.

While investigating the cause, I managed to trigger some errors around a zbscrm_api_keys table; this was probably incidental because it was the first table created, but said table is never actually used other than hard-coded checks for its existence (don't ask me why), so I removed code related to its creation and detection. Removing it from existing installs is out of scope here.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

The most painless way to do this is to set up SQLite via the SQLite Database Integration plugin. Install that on a WordPress site, initialise the site, and then you should be good to go.

Go to the System Status page: /wp-admin/admin.php?page=zerobscrm-systemstatus&tab=status

In trunk, you'll see this message:

Jetpack CRM experienced errors while trying to build it's database tables. Please contact support sharing the following errors: (#306sql)

In the fix/crm/3406-address_sqlite_table_creation_error branch, the error is no more.

@tbradsha tbradsha added [Status] Needs Team Review [Plugin] CRM Issues about the Jetpack CRM plugin labels Jan 5, 2024
@tbradsha tbradsha added this to the crm/6.3.3 milestone Jan 5, 2024
@tbradsha tbradsha requested a review from a team January 5, 2024 21:10
@tbradsha tbradsha self-assigned this Jan 5, 2024
@github-actions github-actions bot added the Admin Page React-powered dashboard under the Jetpack menu label Jan 5, 2024
Copy link
Contributor

github-actions bot commented Jan 5, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@coder-karen
Copy link
Contributor

The most painless way to do this is to set up SQLite via the SQLite Database Integration plugin. Install that on a WordPress site, initialise the site, and then you should be good to go.

What steps / what kind of testing site did you use to be able to do this? I've tried with Jurassic Ninja sites - results in the following error:

Screenshot 2024-01-08 at 08 59 28

Local (by Flywheel) sites - activating the plugin just results in an error saying that 'The SQLite Integration plugin is active, but the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation.'.

Then on a Pressable site, which just resulted in a critical error.

@tbradsha
Copy link
Contributor Author

tbradsha commented Jan 8, 2024

Jurassic Ninja seems to have more general issues with SQLite prior to even getting to our plugin; probably a custom setup preventing WP from installing.

Local (by Flywheel) sites - activating the plugin just results in an error saying that 'The SQLite Integration plugin is active, but the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation.'.

Odd; I didn't have any issues...what version of PHP?

Then on a Pressable site, which just resulted in a critical error.

What was the error there?

@coder-karen
Copy link
Contributor

Noting here that we sorted out the SQLite issues - updating my Local site to use PHP 8.0+ helped.

I did test this in two different environments though and both times I am still seeing 'Jetpack CRM experienced errors' message on the system status page. The first environment is the Local test site, testing first on trunk and then using the branch. Then secondly directly in WP playground, initially testing trunk then the branch.

However in the third scenario it did work - directly creating a WP playground site and going straight to the branch. Having trunk active beforehand seemed to cause the error to stay. Is this expected?

Copy link
Contributor

@coder-karen coder-karen left a comment

Choose a reason for hiding this comment

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

Thinking about this more, it really doesn't matter what happens in trunk before using this branch, as once this is merged the playground is only ever going to use the new code. So 👍 from me.

@tbradsha
Copy link
Contributor Author

tbradsha commented Jan 8, 2024

Yes, if you go from trunk to this branch, I believe it'll continue to show the error because it's stored as a WP option, and as long as that option exists it'll continue to show the message for debug purposes.

@tbradsha tbradsha merged commit 686c911 into fix/crm/3408-detect_sqlite_usage Jan 8, 2024
50 checks passed
@tbradsha tbradsha deleted the fix/crm/3406-address_sqlite_table_creation_error branch January 8, 2024 16:05
tbradsha added a commit that referenced this pull request Jan 8, 2024
* Add database engine check

* Add changelog

* CRM: 3406 - address SQLite table creation error (#34872)

* Remove obsolete database table

* Bypass InnoDB check for SQLite

* Add changelog

* CRM: 3404 - address syntax differences between SQLite and MySQL (#34869)

* Update table alias

The `transaction` alias is a reserved keyword in SQLite.

* Implement engine-agnostic build_group_concat()

* Add changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants