Jump to content

Extending module with own database tables


sunlix
 Share

Recommended Posts

Hi Guys,

just have a short question 'cause I didn't find any hint.

How to create the best upgrading path for modules with own database tables?

I want to add a new column to the database table in the next release of my module, so I have to alter the table.

Where is the best place to add some code for altering my table?

Currently I only had updated the ___install() function with the new column.

Thanks for every hint. :-)

regards,

Sven

Link to comment
Share on other sites

Hi Sven,

An idea off the top of my head (and totally untested): could you make your module a configurable module with a hidden field set to the current module's version. During your init routine you'll get given that value so you just compare it with your module's current version and if your current version is greater then call your update routine to alter the table as needed.

Knowing Ryan, there's probably a way to do this built-in but I'm currently unaware of it.

  • Like 3
Link to comment
Share on other sites

@sunlix: you might want to take a look at how I've handled this issue in the Changelog module.

The approach I took there was adding new configuration option ($this->schema_version, which refers to the schema version currently used) and a constant (SCHEMA_VERSION, which refers to latest available schema version) and until those match it'll run updateDatabaseSchema() method, which takes care of schema updates.

In that case the install routine actually uses an "outdated" schema version, so that module update (on existing installation) and fresh module installation behave exactly the same. That's definitely a question of preference.

This is actually a simplified version of ProcessWire's own SystemUpdater.. and pretty much what @netcarver mentioned above too :)

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...