credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #04986
[Merge] lp:~therp-nl/openupgrade-server/6.1_UTC_fixes into lp:openupgrade-server
Holger Brunn (Therp) has proposed merging lp:~therp-nl/openupgrade-server/6.1_UTC_fixes into lp:openupgrade-server.
Requested reviews:
OpenUpgrade Committers (openupgrade-committers)
Related bugs:
Bug #1034283 in OpenUpgrade Server: "Migration should convert datetime fields to UTC"
https://bugs.launchpad.net/openupgrade-server/+bug/1034283
For more details, see:
https://code.launchpad.net/~therp-nl/openupgrade-server/6.1_UTC_fixes/+merge/126018
--
https://code.launchpad.net/~therp-nl/openupgrade-server/6.1_UTC_fixes/+merge/126018
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~therp-nl/openupgrade-server/6.1_UTC_fixes into lp:openupgrade-server.
=== modified file 'openerp/addons/base/migrations/6.1.1.3/pre-migration.py'
--- openerp/addons/base/migrations/6.1.1.3/pre-migration.py 2012-02-17 15:05:04 +0000
+++ openerp/addons/base/migrations/6.1.1.3/pre-migration.py 2012-09-24 14:06:46 +0000
@@ -11,6 +11,10 @@
logger = logging.getLogger('OpenUpgrade')
me = os.path.realpath( __file__ )
+update_timezone_statement="""update "%(table)s" set "%(column)s"="%(column)s"-
+(interval '1 second')*
+extract(timezone from cast("%(column)s" as timestamp with time zone))"""
+
renames = {
# this is a mapping per table from old column name
# to new column name, e.g.
@@ -82,9 +86,21 @@
cr,
"UPDATE ir_module_module SET demo = false")
+def migrate_timestamps(cr):
+ cr.execute("""
+ select attname,relname from pg_class join pg_attribute
+ on pg_class.oid=pg_attribute.attrelid
+ where pg_attribute.atttypid in
+ (select oid from pg_type where typname='timestamp')
+ and relkind='r'
+ """)
+ for row in cr.fetchall():
+ logger.info('fixing UTC offset for %(table)s.%(column)s' %
+ {'table': row[1], 'column': row[0]})
+ cr.execute(update_timezone_statement %
+ {'table': row[1], 'column': row[0]})
def migrate(cr, version):
- try:
- logger.info("%s called", me)
+ migrate_timestamps(cr)
add_serialization_field(cr)
set_main_company(cr)
openupgrade.rename_columns(cr, renames)
@@ -94,5 +110,3 @@
)
fix_module_ids(cr)
disable_demo_data(cr)
- except Exception, e:
- raise osv.except_osv("OpenUpgrade", '%s: %s' % (me, e))
Follow ups