sunlix Posted October 9, 2014 Share Posted October 9, 2014 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 More sharing options...
netcarver Posted October 9, 2014 Share Posted October 9, 2014 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. 3 Link to comment Share on other sites More sharing options...
teppo Posted October 9, 2014 Share Posted October 9, 2014 @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 4 Link to comment Share on other sites More sharing options...
sunlix Posted October 10, 2014 Author Share Posted October 10, 2014 Yeah, thank you @teppo & @netcarver. It is a nice idea; I'll go further to implement my tiny update routine this way. I apologize if I will borrow some code lines O:-) have a nice weekend! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now