Skip to content

Instantly share code, notes, and snippets.

@prakashpp
Last active February 13, 2016 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakashpp/d30370c34c771ed717f4 to your computer and use it in GitHub Desktop.
Save prakashpp/d30370c34c771ed717f4 to your computer and use it in GitHub Desktop.
Uninstall tryton modules
# -*- coding: utf-8 -*-
import os
import sys
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 uninstall_module(module_name):
cursor.execute("""
SELECT id FROM ir_module_module WHERE name = '%s'
""" % (module_name, ))
data_to_delete = {
"ir_module_module": [cursor.fetchone()[0]]
}
cursor.execute("""
SELECT id, model, db_id FROM ir_model_data
WHERE module = '%s'
""" % (module_name, ))
for id, model, db_id in cursor.fetchall():
data_to_delete.setdefault(model.replace('.', '_'), []).append(db_id)
for table, ids in data_to_delete.iteritems():
query = 'DELETE FROM "' + table + '" WHERE id = ANY(%s);'
cursor.execute(query, (ids, ))
if __name__ == '__main__':
"""A complete migration script to move LN to 3.4 version.
This expects following env variables::
* TRYTOND_DATABASE_URI: postgresql://tryton:tryton@localhost/production
"""
cursor = conn.cursor()
uninstall_module(sys.argv[1])
conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment