Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Prefixing database tables with elefant_

edited September 2012 in Framework

The feature was requested (and it's something I probably should have done from the start) to add elefant_ as a database table prefix. I made a pull request that changes this and seems to be working well:

But since we're already so close to finished with the Elefant 1.3.x betas, I wanted to ask what everyone here thinks, whether we should merge now or wait until the next beta series after this one, whether a migration script should be included, etc.

So, what are everyone's thoughts?


  • Are we adding elefant_ or allowing for a custom prefix? I know sometimes people like to run multiple instances on the same db. This would only allow for one instance.

  • I'm on the fence between simplicity and configurability here. I can see running additional web services against the same database (e.g., a PHP forum app like this one). Having the prefix would avoid potential name clashes with those. And while running multiple Elefant instances on the same database could be made possible, we would need to be explicit that they then potentially share access to each others' data (with an app like the DB Manager, for example). You would only do this if you owned all the sites.

    Of course, that could be a feature too. Data published on one could access data from any or all of the others within the same database connection. That seems like a potential performance/reliability bottleneck in the making, but it is possible. Is it advisable? I would tend to say a better way we should encourage would be to syndicate content between them via APIs, which can scale more easily. Hmm... :)

  • Hmm. Then there is also the problem of extensions and other apps. We'd have to force those to take the prefix as well. Or is that taken care of? I haven't had time to look through the relevant commits yet.

  • Right now it just prefixes the core tables and references to them with elefant_. I'm on the fence whether to define a prefix in the global config and change those references to conf('Database','prefix') though.

    It wouldn't be hard to add a str_replace ('#prefix#', conf('Database','prefix'), $sql) to lib/DB.php that would essentially make it automatic everywhere, and models could even use public $table = '#prefix#model' in that case.

    Apps could be updated easily enough, but we would also have to encourage new apps to use the #prefix# marker in the right way.

  • So there is still the possibility of installed apps clashing with other tables.

    Looking at other systems, it looks like they have gone the route of using $db_prefix = "prefix" in their main app config files. So your conf('Database', 'prefix')

    I tend to like this approach. And there has to be a way to automate checking a prefix instead of the model needing that #prefix#. Can't we just assume that there may be a prefix, check it, if it doesn't exist fallback to just the name?

  • I think the #prefix# may be needed, because the prefix setting would always be set for the core (even if it just defaults to empty to be compatible with existing sites), and models currently assume no prefix when guessing a default table name. Probably best not to change that behaviour since that would break apps that haven't updated themselves. Checking for a table's existence and falling back seems like a really inefficient option too.

    If we add a replacement for #prefix# (or even {$prefix} to be more PHP-like) to DB, then we can simply add #prefix# to table references in any query, and apps no longer have to assume anything about prefixes. Older apps would continue to work without being updated, but to update them we just change public $table = 'foo' to public $table = '#prefix#foo' and the rest happens automatically.

  • Hmm. Ok. I'd say go for it then.

  • Hopefully I have a bit of time in the next day or so to get to that. Shouldn't take long, but I'm knee-deep in ActionScript at the moment, haha

  • Alright, prefixes are in master! The prefix defaults to empty so existing sites will continue to work fine, but defaults to "elefant_" in the installer so new sites will use that. Testing so far seems pretty solid. Existing apps will continue working fine, and can be updated by adding #prefix# to table references so as to match the new Elefant naming style.

  • Actionscript?!

    And awesome! I'll pull it and give it a go.

  • Yeah, we're making an interactive 3D virtual tour of three companies, with animated characters and clickable spots to branch off into different areas. Pretty cool actually. I'm basically just splicing it together, the animations are pre-rendered then stitched together with pause spots and clickable choices. Easy stuff, but looks cool :)

Sign In or Register to comment.