Skip to content

Instantly share code, notes, and snippets.

@sharoonthomas
Last active August 29, 2015 14:17
Show Gist options
  • Save sharoonthomas/d173234e625d5a8ce90a to your computer and use it in GitHub Desktop.
Save sharoonthomas/d173234e625d5a8ce90a to your computer and use it in GitHub Desktop.
For the sake of consistency, the module ups was renamed to shipping_ups. Tryton's migration API does not provide a straightforward way to rename modules as its an exceptional case. This file gives you the code you need to make the migration
# -*- coding: utf-8 -*-
import os
import psycopg2
# Connect to tryton database with database uri.
#
# Example: postgres://tryton:tryton@localhost/production
conn = psycopg2.connect(os.environ.get('TRYTOND_DATABASE_URI'))
conn.set_client_encoding('UTF8')
def rename_ups_module():
"""UPS module has been renamed to shipping_ups, hence rename it in
database also.
"""
# Update ir_module_module entry.
# Just a name change from `ups` to `shipping_ups`
cursor.execute("""
UPDATE ir_module_module
SET name = 'shipping_ups'
WHERE name = 'ups'
""")
# Update data related to ups
#
# Tryton stores the information about records created from
# XML in ir.model.data, so it can update the information
# with module upgrades.
#
# Update the name of module there too.
cursor.execute("""
UPDATE ir_model_data
SET module = 'shipping_ups'
WHERE module = 'ups';
""")
# Tryton views store the module name in them to load the
# view xml filed from FS at runtime. They need to be update
# too
cursor.execute("""
UPDATE ir_ui_view
SET module = 'shipping_ups'
WHERE module = 'ups';
""")
if __name__ == '__main__':
cursor = conn.cursor()
rename_ups_module()
conn.commit()
@sharoonthomas
Copy link
Author

Usage instructions:

  1. Set the database connection as a URI in the environment
export TRYTOND_DATABASE_URI=postgres://tryton:tryton@localhost/production
  1. Run the file
python migrate_ups_module.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment