[PATCH] [Wok] Upgrade objectstore schema.

From: Paulo Vital <pvital@linux.vnet.ibm.com> This patch is part of the solution for the Ginger Issue #51 and it's a basic dependence for the following plugins' patches: + [Kimchi] Update Kimchi objectstore versioning. + [Ginger] Issue #51 - Update objectstores with 'Version' field. + [GingerBase] Issue #51 - Update objectstores with 'Version' field. With the new structure of the objectstore changed in Wok 2.0.0, the schema of the objectstore file (when used by any plugin) needs to be checked and, if necessary, updated to reflect the new structure. This patch adds to utils.py file some common methods to support the operations in the plugin's objectstore files. These methods were moved from Kimchi plugin since they will be used by other plugins to do the same. Paulo Vital (1): Upgrade objectstore schema. src/wok/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) -- 2.5.0

From: Paulo Vital <pvital@linux.vnet.ibm.com> With the new structure of the objectstore changed in Wok 2.0.0, the schema of the objectstore file (when used by any plugin) needs to be checked and, if necessary, updated to reflect the new structure. This patch adds to utils.py file some common methods to support the operations in the plugin's objectstore files. These methods were moved from Kimchi plugin since they will be used by other plugins to do the same. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- src/wok/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/wok/utils.py b/src/wok/utils.py index 8c8973a..997adf3 100644 --- a/src/wok/utils.py +++ b/src/wok/utils.py @@ -26,6 +26,7 @@ import os import psutil import pwd import re +import sqlite3 import subprocess import traceback import xml.etree.ElementTree as ET @@ -504,3 +505,47 @@ def convert_data_size(value, from_unit, to_unit='B'): break return ret + + +def get_objectstore_fields(objstore=None): + """ + Return a list with all fields from the objectstore. + """ + if objstore is None: + wok_log.error("No objectstore set up.") + return None + conn = sqlite3.connect(objstore, timeout=10) + cursor = conn.cursor() + schema_fields = [] + sql = "PRAGMA table_info('objects')" + cursor.execute(sql) + for row in cursor.fetchall(): + schema_fields.append(row[1]) + return schema_fields + + +def upgrade_objectstore_schema(objstore=None, field=None): + """ + Add a new column (of type TEXT) in the objectstore schema. + """ + if (field or objstore) is None: + wok_log.error("Cannot upgrade objectstore schema.") + return False + + if field in get_objectstore_fields(objstore): + # field already exists in objectstore schema. Nothing to do. + return False + try: + conn = sqlite3.connect(objstore, timeout=10) + cursor = conn.cursor() + sql = "ALTER TABLE objects ADD COLUMN %s TEXT" % field + cursor.execute(sql) + wok_log.info("Objectstore schema sucessfully upgraded: %s" % objstore) + conn.close() + except sqlite3.Error, e: + if conn: + conn.rollback() + conn.close() + wok_log.error("Cannot upgrade objectstore schema: %s" % e.args[0]) + return False + return True -- 2.5.0

Did you send the patch ? I just received the cover ... Rodrigo On 12/14/2015 11:45 AM, pvital@linux.vnet.ibm.com wrote:
From: Paulo Vital <pvital@linux.vnet.ibm.com>
This patch is part of the solution for the Ginger Issue #51 and it's a basic dependence for the following plugins' patches: + [Kimchi] Update Kimchi objectstore versioning. + [Ginger] Issue #51 - Update objectstores with 'Version' field. + [GingerBase] Issue #51 - Update objectstores with 'Version' field.
With the new structure of the objectstore changed in Wok 2.0.0, the schema of the objectstore file (when used by any plugin) needs to be checked and, if necessary, updated to reflect the new structure.
This patch adds to utils.py file some common methods to support the operations in the plugin's objectstore files. These methods were moved from Kimchi plugin since they will be used by other plugins to do the same.
Paulo Vital (1): Upgrade objectstore schema.
src/wok/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
-- 2.5.0
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
participants (3)
-
Aline Manera
-
pvital@linux.vnet.ibm.com
-
Rodrigo Trujillo