Give each wordpress user their own database instance.#76
Closed
jzohrab wants to merge 1 commit intoHugoFara:devfrom
Closed
Give each wordpress user their own database instance.#76jzohrab wants to merge 1 commit intoHugoFara:devfrom
jzohrab wants to merge 1 commit intoHugoFara:devfrom
Conversation
Instead of having table name prefixes, we can just have LWT auto-create completely separate databases for each WP user, so each WP user can manage their own database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Instead of having table name prefixes, we can just have LWT auto-create completely separate databases for each WP user, so each WP user can manage their own database. With this, we can get rid of $tbpref everywhere, and fix all the DB migrations.
This change is much simpler than creating user tables, and modifying all data structures and queries to support a multi-tenant db architecture!!!
Changes
Pretty minimal, actually. Essentially, every time a WP user tries to connect to the DB, the file
inc/wp_logincheck.phpjust appends the user's WP ID to the$rootdbnamespecified in the connect file, and sets the new global$dbnamewhich is used everywhere else.Demo
I installed wordpress locally, and on the initial wp sample page I added a link to
[lwt/wp_lwt_start.php](http://localhost:8888/wordpress/lwt/wp_lwt_start.php)as given in the docs. In WP admin, I created a few users. I then logged in to each user and clicked the link, and the databases were created. Each user can then install their own demo, create their own texts etc, and the $dbname is set correctly.e.g., I created a new WP user, "newguy", which had user_id=4:
Prior to newguy's wordpress login:
newguy logs in and clicks the LWT link, and new db is created
and everything works as expected. eg on the UI:
What this lets us do
** Docs needed for existing WP users to migrate**
For each WP user, the WP admin would need to do the following:
(We might be able to write some helper scripts for this, but I personally would rely on the community for input. If they are savvy enough to set up the integrations etc for WP, then perhaps they can get into some other tasks too. We do the best we can, but this is still an open source project, and not a paid product!)