Commit fe74c40d authored by Sebastien Robin's avatar Sebastien Robin

upgrader: improve sql table checking after upgrade, automatically add/remove/alter tables

Use portal_catalog.upgradeSchema to do all required changes on sql tables. This improve
previous state since before we were only recreating missing tables.
parent f3c81817
<property_sheet_list>
<portal_type id="Template Tool">
<item>TemplateToolBusinessTemplateInstallationConstraint</item>
<item>TemplateToolTableExistenceConstraint</item>
<item>TemplateToolTableConsistencyConstraint</item>
<item>TemplateToolWorkflowChainConsistencyConstraint</item>
</portal_type>
</property_sheet_list>
\ No newline at end of file
......@@ -32,7 +32,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateToolTableExistenceConstraint</string> </value>
<value> <string>TemplateToolTableConsistencyConstraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......
......@@ -34,7 +34,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>table_existence_constraint</string> </value>
<value> <string>table_consistency_constraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......@@ -42,7 +42,7 @@
</item>
<item>
<key> <string>script_id</string> </key>
<value> <string>TemplateTool_checkTableExistence</string> </value>
<value> <string>TemplateTool_checkTableConsistency</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -51,25 +51,12 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Check for some table existence according to the create table list.\n
If `fixit` is True, then it uses the associated sql_method to create it.\n
Check for some table consistency according to the create table list.\n
If `fixit` is True, then it will create/drop table or alter existing tables\n
"""\n
create_table_list = [\n
# ("category", "z_create_category"), # example\n
("catalog_full_text", "z_create_catalog_fulltext"),\n
]\n
sql_catalog = context.portal_catalog.getSQLCatalog()\n
table_list = [r[0] for r in sql_catalog.z_show_tables(table="not needed so far")]\n
report_list = []\n
for create_table_information in create_table_list:\n
if not callable(getattr(sql_catalog, create_table_information[1], None)):\n
continue\n
if create_table_information[0] not in table_list:\n
if fixit:\n
getattr(sql_catalog, create_table_information[1], None)()\n
else:\n
report_list.append("Table `%s` not created (%s)" % create_table_information)\n
return report_list\n
portal = context.getPortalObject()\n
show_source = not(fixit)\n
return [portal.portal_catalog.upgradeSchema(src__=show_source)]\n
</string> </value>
</item>
<item>
......@@ -78,7 +65,7 @@ return report_list\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateTool_checkTableExistence</string> </value>
<value> <string>TemplateTool_checkTableConsistency</string> </value>
</item>
</dictionary>
</pickle>
......
Template Tool | TemplateToolBusinessTemplateInstallationConstraint
Template Tool | TemplateToolTableExistenceConstraint
Template Tool | TemplateToolTableConsistencyConstraint
Template Tool | TemplateToolWorkflowChainConsistencyConstraint
\ No newline at end of file
TemplateToolBusinessTemplateInstallationConstraint
TemplateToolWorkflowChainConsistencyConstraint
TemplateToolTableExistenceConstraint
\ No newline at end of file
TemplateToolTableConsistencyConstraint
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment