Forum OpenACS Development: UPGRADE Scripts PLEASE

Collapse
Posted by Jon Griffin on
I just went to upgrade a 4.5 to the lastest dev version and I notice that although the datamodels have changed (acs-object for example), no one is writing upgrade scripts.

If you want to guarantee that no one upgrades, please continue this practice. If, on the other hand, you want to follow what was set out as before, ADD them. It is not that hard to write a little script to do updates. If something breaks then it still needs to be documented.

It was agreed upon that from the Beta release of 4.5 on ALL data model changes would have a script for upgrade. The APM already has this capability, use it please, so everyone doesn't have to run diff and figure out what changed.

Collapse
Posted by Don Baccus on
Ouch - yes, we need to provide upgrade scripts.  No bout adout it.
Collapse
Posted by Jon Griffin on
I have started making them for the packages I use. Someone will have to do Oracle and I will post what I did when I finish (very soon).

P.S. What a pain in the a$#

Collapse
Posted by Jon Griffin on
The acs-kernel script is there. I am having some connection problems at home and can't check it very will. If someone else wants to do a cvs co and try it let me know.
Collapse
Posted by Jon Griffin on
acs-subsite is done.
Collapse
Posted by Jon Griffin on
Can someone please explain to my why it was necessary to modify the search_observer_queue table in search-tables-create.sql?

This works in 7.2, but I am not sure if it works in 7.1:


alter table search_observer_queue rename column date to event_date;

If this works in 7.1 then search is also done.

Collapse
Posted by Yonatan Feldman on
because date is a reserved word in oracle.
Collapse
Posted by Jon Griffin on
I forgot about Oracle reserved words, but this would have really bitten some people if there wasn't a script or even a doc.
Collapse
Posted by Vinod Kurup on
In order for the APM to notice that there is a new upgrade script available, we need to keep the version-number in the .info files up-to-date.

Scenario:

Jon's running OpenACS 4.5 which has version 4.0a of the Download package. I decide to add a great new feature to Download which requires a new table. So, I add the new SQL to download-create.sql and then dutifully create an upgrade file - upgrade-4.0a-4.1.sql. I then update the .info file and change the version to 4.1.

Jon does a CVS update and then runs the package installer to see if any of his installed packages have been upgraded. The installer tells him that Download v.4.1 is now available and when Jon selects it, the installer runs the appropriate upgrade script.

Now, let's say that, a couple days later, I decide to add another new SQL feature. Can I add it to that first upgrade script? No! Since Jon's already upgraded, he'll never get it and his install will probably break. So, I guess the rule is: Whenever you commit a change to a datamodel file, upgrade the version in the .info file (eg. 4.1.1) and create a new upgrade file (upgrade-4.1-4.1.1.sql).

Sidetrack: For some reason, the last CVS merge from the 4.5 branch to the HEAD branch didn't merge all the .info files properly. So, a lot of the core package .info files have versions < 4.5 even though they are all = 4.5 in the 4.5 branch. (Confused yet?). In any case, I'm going to go through and fix that now.

What all package developers should do now:

  1. Do a 'cvs log' on all the .sql files in your package.
    $ cvs log bookmarks-create.sql
    Working file: bookmarks-create.sql
    head: 1.19
    branch:
    locks: strict
    access list:
    symbolic names:
    	oacs-4-5-final: 1.18
    	oacs-4-5-rc-1: 1.18
    	don-merge-1: 1.18
    
  2. Look for the tag "oacs-4-5-final" and compare that to the tag listed next to "head:". If they are the same - you're fine. If not, you need to do a diff between those 2 versions and see what the difference is. (cvs diff -r 1.18 -r 1.19 bookmarks-create.sql)
  3. create an upgrade script. The starting version should be the current version of your package (look in the .info file). Choose a new version number. So, for this bookmarks example, it would be upgrade-4.1.1b-4.1.2.sql. Put this file in a separate 'upgrade' directory (i.e. packages/bookmarks/sql/postgresql/upgrade/)

    Repeat steps 1-3 for each SQL file in your package.

  4. Go to the APM and upgrade the version on your package. While you're there, update the description, author-contact info and the file-list
This is, at least, how I think things should work. Please let me know if I'm mistaken 😊
Collapse
Posted by Ola Hansson on
Vinod,

let's say I cvs update bookmarks and find _several_ upgrade scripts under packages/bookmarks/sql/postgresql/upgrade, none of which I have applied before... Will the APM upgrade to the latest version automatically or how will it behave - do you know?

Collapse
Posted by Vinod Kurup on
From what I recall, the APM now handles this intelligently. It should run any scripts with a starting number GREATER THAN OR EQUAL to your current version AND an ending number LESS THAN OR EQUAL to your desired version (i.e. the version currently in the .info file of the package you're upgrading). So, as an example, if you're currently at version 4.0.1 and the version-number in the .info file is 4.4, the APM would run upgrade-4.0.1-4.1.sql, then upgrade-4.1-4.3.sql and then upgrade-4.3-4.3.2a.sql, but never upgrade-4.0-4.0.1.sql.
Collapse
Posted by Jun Yamog on
Hi Vinod,

Can you cut and paste that very informative post about upgrading into the docs?  I never knew about this is possible.  I all I thought was to run the upgrade scripts manually.

I hope the post gets into documentation so new developers does not have to dig the bboards for this info.  Or old developers like me will know about this.

Collapse
Posted by Yonatan Feldman on
you are right jon, i am all for writing upgrade scripts. how about some guidelines on how to 'tic' the version number of a package when we make a data model change, so that the upgrade scripts will work and to keep version numbers consistent. that is, if i change something in acs-kernel (currenlty version 4.5) do i change the version number to 4.5.1? also, how do i do this, through the UI or can i change it directly in the file? there are several places that the number needs to change, including the provides tag. this brings me to my last question: do i change the packages that require acs-kernel 4.5 to require kernel 4.5.1?

tia

Collapse
Posted by Yonatan Feldman on
can people also ostart creating drop scripts and keep them up to date. they are incredibly useful when they are there and it is terribly frustrating when they are not.
Collapse
Posted by Jon Griffin on
I will leave it to Don to make the final decision on versions, but I think you were right in most respects. If I am working on the kernel and fix something (not a major new functionallity) then definitly bump the version up. You only need to bump the requires on a package that absolutly has to use the new version. If it is just a code fix or addition of a proc or something the APM should be working to know version >= 4.5.

I thought there was a doc on versions or at least a mention of it somewhere. We should have a standard on versioning though. The original intent at AD was that the core was released with the same major.minor version, but all the non-core packages could have their own versions. This got screwed up and you get packages like news that are version 4.1b. This says it is version 4.1 beta (the letters are supposed to mean something). In reality this package should be named .1b or 1.0b to more accuratly describe it.

I hope this makes sense and it should be on the development do's and don'ts somewhere.

Collapse
Posted by Vinod Kurup on
Argh! another problem... I mentioned above that not all the files in openacs-4-5 got merged into the CVS HEAD. I thought that it was just .info files and some doc files (which I manually merged). I just noticed that some bugfixes didn't get merged over, as well. Specifically (and ironically), I fixed a bug so that upgrade-checking in the APM worked (PG). This was in 4.5, but didn't get merged into the HEAD. When Jon made the acs-kernel upgrade script, he noticed that apm_package_version__upgrade_p was changed, so he properly dropped the function and recreated the "new" one, which, of course, is the old buggy one. Fortunately, he didn't bump the version yet, so I'm going to fix the problem in CVS, touch up the acs-kernel upgrade scripts, and look to see if any other code didn't get merged properly. Anyone that manually upgraded using Jon's script should drop apm_package_version__upgrade_p and load the version that will be in CVS in a few minutes 😊

Other comments:

  • I think it's better to adjust the .info file via the UI, because there are multiple places to set it (as Yon notes), and if you do it via the UI, the APM automatically upgrades the version on your system to the new version *without* running the upgrade scripts (since you've presumably been developing and testing before you change the .info file). You do need to remember to change the 'provides' as well in the 'Manage Dependencies' section.
  • Should module owners attach a CVS tag to their module when they upgrade the version? This would make it easier to track which changes have occurred between versions, now that module versions will not correlate 1-to-1 to openacs versions. Is it even possible to TAG just one module?
  • There is a doc on version numbering, but it doesn't discuss these issues - https://openacs.org/doc/openacs-4/eng-standards-versioning.html
  • Setting the "provides" is a no-brainer. Setting the "requires" is much more complex. Packages which currently 'require' your package don't necessarily belong to you and may not be in your control - e.g. my proprietary rule-the-world v0.1d package (in stores soon!). This is going to need some good communication between packages (via detailed ChangeLogs?) so a package knows whether they need to bump-up their 'requires'
Collapse
Posted by Jon Griffin on
Vinod,
Please post when you have finished that so I can test it.
Thanks
Collapse
Posted by Vinod Kurup on
I re-fixed the APM bug, edited the upgrade script, created an oracle upgrade script and  bumped the acs-kernel version to 4.5.1. I found a few more changes that didn't get merged in, but fortunately none affect the datamodel. I've merged these in again.

Doing this made me realize how cool 'create or replace' is. It also makes sense to keep Oracle packages/PG functions in their own files (i.e. separate from datamodel creation, view creation, etc). This makes it possible to simply source the new files, rather than recopying the entire function in the upgrade script.

Collapse
Posted by Lars Pind on
As you may have noticed, we lost some data on the .LRN bug-tracker during the upgrade process.

It turns out the reason is that the APM correctly loads all the upgrade-scripts between two versions, also if there are more than one script.

Unfortunately, it loads them in reverse (or at least not the correct) order, which is what caused a later upgrade script to fail and data to get lost.

I'm looking into fixing it now, but if anybody knows off-hand what the problem is, they can save me a bit of trouble.

I'm trying to find out just what is happening in "apm_data_model_scripts_find" :)

/Lars

Collapse
Posted by Jeff Davis on
Lars, if you are running on postgresql 7.2 it might be related to
this bug: https://openacs.org/sdm/one-baf.tcl?baf_id=1347
which I have a patch for but which has not been applied since
I did not make the corresponding changes in the oracle version.

See the patch to see what is going on...

(although looking at  apm_upgrade_script_compare it looks like
the compare is being done in tcl so the collating order in postresql
shoudl not matter).  Huh

Collapse
Posted by Lars Pind on
I'm running 7.1, and I've found the bug:

"apm_upgrade_script_compare" had two different queries, both of which were named "test", so the query dispatcher happily went and used the same query twice, and "apm_upgrade_script_compare" would always return 1 (for some reason, not sure why 1).

There may be other problems, I don't know.

I'll be committing once I've run a few more tests.

/Lars