-
Notifications
You must be signed in to change notification settings - Fork 341
Fixing upgrade script failures when a dbprefix is defined in database.php #143
base: master
Are you sure you want to change the base?
Conversation
…hey break the dbprefix config setting, and automatically get added by CI elsewhere
Cool. |
Just noticed that you'd also need to add the {PRE}s to openvbx.sql in the root directory. Sorry about this pull request having multiple commits associated with it. If you run a diff on it, the only differences are the ones related the the dbprefix issue. From now on I'll create a new branch with merged with master, so you don't see any unrelated commits. |
I've merged this locally and have started testing. I think that the install process should have an advanced option to select the db-prefix as well so I'll be adding that in while I test. |
There's a fun problem here that may make this hard to do. I've run in to this in the db->query method:
That effectively prevents the swap_pre from being processed if there's no dbprefix to swap in, essentially denying us the ability to have optional prefixes. I'm trying to find a way around this without creating too much headache, but I'm not confident that any work around will be without caveats that make creating upgrades harder. |
I'm gonna shelf this for a later update. I think I want to change to using a prefix by default but need to better plan how to manage the upgrade process. |
This one is still a touchy subject as CodeIgniter has some very strict handling around the db-prefix. I'm thinking that the correct course of action here would be to start using a db-prefix in new installs of OpenVBX. All in all its a good idea but, as is the case with something like this, it would require lots of testing. I still want to do this. |
Thanks for keeping this issue alive. Too bad there isn't an easier way to implement this. |
Yeah, I was so close and then CodeIgniter slammed the door shut in my face. |
I ran into this issue when attempting to upgrade from version 0.90 to version 1. This commit partially addresses issues where OpenVBX's upgrade scripts cannot run because there is a dbprefix set in database.php.
For example if
$db["default"]["dbprefix"] = "vbx_"
, then the SQL in /updates/47.sqlUPDATE
settingsSET
value= '0.91' WHERE
name= 'version'
... won't execute and the upgrade process will halt and throw an error.This fix required that
$db["default"]["swap_pre"] = "{PRE}"
be added to databases.php and the string{PRE}
be placed before the names of any tables in any raw SQL executed by CodeIgniter. CodeIgniter's DB driver takes care of the dirty work, and swaps the swap_pre string with the db_prefix string for raw query strings. To see how this works, see line 257 of CodeIgniter's DB_driver.php.I only added the swap_pre string the updates files 47 and up, because those were the only files that affected our upgrade from version 0.90 to 1.0. I didn't think the scenario where someone upgrading from an earlier version would run into this same issue was realistic. I also looked through OpenVBX's code for other instances where there were raw SQL was being passed to
$ci->db->query()
but didn't encounter any.I also, defined the swap_pre string in the database-sample.php -- but obviously, for this to work, the swap_pre string would need to be set to "{PRE}" in database.php.