>>>> ... >>>> Or, if you *do* feel like just adding a dependency on TracSqlHelperScript, >>>> like I ended up doing, you could basically just copy all of the setup code >>>> in MultiRepoSearchPlugin here[1] and adjusting it for your needs. In >>>> addition to demonstrating schema definition and table creation, it also >>>> uses >>>> Trac's system table to track what upgrades need to occur, and a neat little >>>> upgrade-steps-based-on-current-version framework thingie that I copied from >>>> TracHours. (That's the `version()` and `steps =` stuff.) I *think* this >>>> is >>>> considered The Right Way to manage upgrades in Trac plugins these days. >>> >>> Thanks. I found an example in Subtickets plugin and will look at >>> TracHours, too. >> >> Any advice on how to add fields to a private table in an upgrade script? > > By fields you mean columns, right?
Yes. > Because ALTER TABLE doesn't work for all supported backends equally > well, in general you'll want to > * create a new temporary table as duplicating the existing one > * delete existing table > * re-create table with additional column > * populate new table from copy of previous table > * delete copy of previous table > > That's the general pattern, that I've found in Trac core as well as in > some plugins. I've done it lately too [1], and with unit test coverage > for such upgrade modules I'm quite sure, that it works. > > Steffen Hoffmann Thanks. What I found in SubticketsPlugin was: * Copy the data from the existing tables into Python hashes * Drop the tables * Create the tables for the new schema * Insert the saved data Interestingly, there was no logic to only do this if the schema was out of date. Maybe that was OK there but it seemed wrong. In my adaptation, I only save and create if the version changed. Seems to work. So far. <fingers crossed> -- You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to trac-dev@googlegroups.com. To unsubscribe from this group, send email to trac-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en.