Connexions/cnx-upgrade — pull request #40 by karenc (2013-12-15 00:12:52+00:00)
Title: Revert 081836 and fix minor version script on invalid data again

Fix collection minor version script for some invalid data in db

Some modules in some collection trees are newer than the collections
themselves in the database. We probably won't have this in the future
but the script needs to deal with it. The script doesn't create minor
versions in those cases.

Example:

col10233 was "revised" at 2004-06-24 08:12:24.875-05.

In the collection tree are m12050, m12049, m12048, m12047.

The "revised" column for these modules are:

moduleid | version | revised
----------+---------+-------------------------------
m12047 | 1.1 | 2004-06-24 17:10:47.545195-05
m12048 | 1.1 | 2004-06-24 17:12:03.076229-05
m12049 | 1.1 | 2004-06-24 17:52:13.317586-05
m12050 | 1.1 | 2004-06-24 18:10:23.192922-05

The modules were published after the collection was published.

So I reverted 081836 and this is the actual fix:
```
$ git diff 081836^.. cnxupgrade/upgrades/create_collection_minor_versions.py
diff --git a/cnxupgrade/upgrades/create_collection_minor_versions.py b/cnxupgrade/upgrades/create_collection_minor_versions
index 2cb311d..61e7e74 100644
--- a/cnxupgrade/upgrades/create_collection_minor_versions.py
+++ b/cnxupgrade/upgrades/create_collection_minor_versions.py
@@ -83,8 +83,9 @@ def create_collection_minor_versions(cursor, collection_ident):

# gather all relevant module versions
sql = '''SELECT DISTINCT(m.module_ident), m.revised FROM modules m
- WHERE m.revised > %s AND m.revised < %s AND m.uuid = (
- SELECT uuid FROM modules WHERE module_ident = %s)
+ WHERE m.revised > %s AND m.revised < %s AND
+ m.uuid = (SELECT uuid FROM modules WHERE module_ident = %s) AND
+ m.revised > (SELECT revised FROM modules WHERE module_ident = %s)
ORDER BY m.revised
'''

@@ -93,7 +94,7 @@ def create_collection_minor_versions(cursor, collection_ident):
for module_ident, portal_type in get_collection_tree(collection_ident,
cursor):
if portal_type == 'Module':
- cursor.execute(sql, [this_revised, next_revised, module_ident])
+ cursor.execute(sql, [this_revised, next_revised, module_ident, module_ident])

# get all the modules with the same uuid that have been published
# between this collection version and the next version
```