Improve migration

bzr revid: ced-cbaca50e19737f294c7a3704ef97981ce0469ac6
This commit is contained in:
ced 2006-12-28 14:41:28 +00:00
parent 65883455f5
commit a23a39033e
7 changed files with 346 additions and 10 deletions

View File

@ -238,16 +238,18 @@ def load_modules(db, force_demo=False, status={}, update_module=False):
if force_demo:
force.append('demo')
if update_module:
cr.execute("select name from ir_module_module where state in ('installed', 'to install', 'to upgrade')")
cr.execute("select name from ir_module_module where state in ('installed', 'to install', 'to upgrade','to remove')")
else:
cr.execute("select name from ir_module_module where state = 'installed'")
cr.execute("select name from ir_module_module where state in ('installed', 'to upgrade', 'to remove')")
module_list = [name for (name,) in cr.fetchall()]
graph = create_graph(module_list, force)
load_module_graph(cr, graph, status)
pool = pooler.get_pool(cr.dbname)
cr.commit()
if update_module:
cr.execute("select id,name from ir_module_module where state in ('to remove')")
for mod_id, mod_name in cr.fetchall():
pool = pooler.get_pool(cr.dbname)
cr.execute('select model,res_id from ir_model_data where not noupdate and module=%s order by id desc', (mod_name,))
for rmod,rid in cr.fetchall():
#
@ -255,10 +257,9 @@ def load_modules(db, force_demo=False, status={}, update_module=False):
# I can not use the class_pool has _table could be defined in __init__
# and I can not use the pool has the module could not be loaded in the pool
#
mod_table = pool.get(rmod)._table
if not mod_table:
raise 'Error, could not find the _table of the object '+rmod
cr.execute('delete from '+mod_table+' where id=%d', (rid,))
uid = 1
print rmod
pool.get(rmod).unlink(cr, uid, [rid])
cr.commit()
#
# TODO: remove menu without actions of childs
@ -272,6 +273,6 @@ def load_modules(db, force_demo=False, status={}, update_module=False):
cr.execute("update ir_module_module set state=%s where state in ('to remove')", ('uninstalled', ))
cr.commit()
cr.commit()
pooler.restart_pool(cr.dbname)
cr.close()

View File

@ -63,6 +63,12 @@ class ir_property(osv.osv):
'company_id': fields.many2one('res.company', 'Company'),
'fields_id': fields.many2one('ir.model.fields', 'Fields', ondelete='cascade', required=True)
}
def unlink(self, cr, uid, ids, context={}):
if ids:
cr.execute('delete from ir_model_fields where id in (select fields_id from ir_property where (fields_id is not null) and (id in ('+','.join(map(str,ids))+')))')
res = super(ir_property, self).unlink(cr, uid, ids, context)
return res
def get(self, cr, uid, name, model, res_id=False, context={}):
cr.execute('select id from ir_model_fields where name=%s and model=%s', (name, model))
res = cr.fetchone()

View File

@ -410,8 +410,9 @@ class orm(object):
# set the field to the default value if any
if self._defaults.has_key(k):
default = self._defaults[k](self, cr, 1, {})
cr.execute("UPDATE %s SET %s='%s' WHERE %s is NULL" % (self._table, k, default, k))
cr.commit()
if not (default is False):
cr.execute("UPDATE %s SET %s='%s' WHERE %s is NULL" % (self._table, k, default, k))
cr.commit()
# add the NOT NULL constraint
try:
cr.execute("ALTER TABLE %s ALTER COLUMN %s SET NOT NULL" % (self._table, k))

View File

@ -0,0 +1,90 @@
##############################################################################
#
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__author__ = 'Gaetan de Menten, <ged@tiny.be>'
__version__ = '0.1.0'
import psycopg
import optparse
import ConfigParser
# -----
parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
group = optparse.OptionGroup(parser, "Database related options")
group.add_option("--db_host", dest="db_host", help="specify the database host")
group.add_option("--db_port", dest="db_port", help="specify the database port")
group.add_option("-d", "--database", dest="db_name", help="specify the database name")
group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
parser.add_option_group(group)
options = optparse.Values()
options.db_name = 'terp' # default value
parser.parse_args(values=options)
if hasattr(options, 'config'):
configparser = ConfigParser.ConfigParser()
configparser.read([options.config])
for name, value in configparser.items('options'):
if not (hasattr(options, name) and getattr(options, name)):
if value in ('true', 'True'):
value = True
if value in ('false', 'False'):
value = False
setattr(options, name, value)
# -----
host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
name = "dbname=%s" % options.db_name
user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
cr = db.cursor()
# --------------- #
# remove old menu #
# --------------- #
cr.execute("delete from ir_ui_menu where (id not in (select parent_id from ir_ui_menu where parent_id is not null)) and (id not in (select res_id from ir_values where model='ir.ui.menu'))")
cr.commit()
# --------------- #
# remove ir_value #
# --------------- #
cr.execute("delete from ir_values where model = 'ir.ui.menu' and res_id is null")
cr.commit()
cr.close()

View File

@ -0,0 +1,83 @@
##############################################################################
#
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__author__ = 'Gaetan de Menten, <ged@tiny.be>'
__version__ = '0.1.0'
import psycopg
import optparse
import ConfigParser
# -----
parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
group = optparse.OptionGroup(parser, "Database related options")
group.add_option("--db_host", dest="db_host", help="specify the database host")
group.add_option("--db_port", dest="db_port", help="specify the database port")
group.add_option("-d", "--database", dest="db_name", help="specify the database name")
group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
parser.add_option_group(group)
options = optparse.Values()
options.db_name = 'terp' # default value
parser.parse_args(values=options)
if hasattr(options, 'config'):
configparser = ConfigParser.ConfigParser()
configparser.read([options.config])
for name, value in configparser.items('options'):
if not (hasattr(options, name) and getattr(options, name)):
if value in ('true', 'True'):
value = True
if value in ('false', 'False'):
value = False
setattr(options, name, value)
# -----
host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
name = "dbname=%s" % options.db_name
user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
cr = db.cursor()
# --------------- #
# remove old menu #
# --------------- #
cr.execute("delete from ir_ui_menu where (id not in (select parent_id from ir_ui_menu where parent_id is not null)) and (id not in (select res_id from ir_values where model='ir.ui.menu'))")
cr.commit()
cr.close()

View File

@ -0,0 +1,148 @@
##############################################################################
#
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__author__ = 'Gaetan de Menten, <ged@tiny.be>'
__version__ = '0.1.0'
import psycopg
import optparse
import ConfigParser
# -----
parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
group = optparse.OptionGroup(parser, "Database related options")
group.add_option("--db_host", dest="db_host", help="specify the database host")
group.add_option("--db_port", dest="db_port", help="specify the database port")
group.add_option("-d", "--database", dest="db_name", help="specify the database name")
group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
parser.add_option_group(group)
options = optparse.Values()
options.db_name = 'terp' # default value
parser.parse_args(values=options)
if hasattr(options, 'config'):
configparser = ConfigParser.ConfigParser()
configparser.read([options.config])
for name, value in configparser.items('options'):
if not (hasattr(options, name) and getattr(options, name)):
if value in ('true', 'True'):
value = True
if value in ('false', 'False'):
value = False
setattr(options, name, value)
# -----
host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
name = "dbname=%s" % options.db_name
user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
cr = db.cursor()
# ------------------------- #
# change some columns types #
# ------------------------- #
def change_column(cr, table, column, new_type, copy):
commands = [
"ALTER TABLE %s RENAME COLUMN %s TO temp_column" % (table, column),
"ALTER TABLE %s ADD COLUMN %s %s" % (table, column, new_type),
"ALTER TABLE %s DROP COLUMN temp_column" % table
]
if copy:
commands.insert(
2,
"UPDATE %s SET %s=temp_column::%s" % (table, column, new_type))
for command in commands:
cr.execute(command)
#change_column(cr, 'crm_case', 'date_closed', 'timestamp', True)
cr.commit()
# -------------------- #
# add module if needed #
# -------------------- #
cr.execute("SELECT name FROM ir_module_module")
if not cr.rowcount:
for module in set(['base', 'marketing', 'subscription', 'account', 'base_partner_relation', 'audittrail', 'account_followup', 'product', 'hr', 'l10n_simple', 'crm', 'stock', 'hr_timesheet', 'purchase', 'report_purchase', 'mrp', 'sale', 'report_sale', 'delivery', 'project', 'sale_crm', 'hr_timesheet_project', 'scrum', 'report_project',
'account_followup',
'account',
'audittrail',
'base_partner_relation',
'crm',
'delivery',
'edi',
'hr_evaluation',
'hr_expense',
'hr',
'hr_timesheet_invoice',
'hr_timesheet_project',
'hr_timesheet',
'l10n_simple',
'marketing',
'mrp',
'network',
'product',
'project',
'purchase',
'report_crm',
'report_project',
'report_purchase',
'report_sale',
'sale_crm',
'sale',
'sandwich',
'scrum',
'stock']):
cr.execute("INSERT INTO ir_module_module (name, state) VALUES ('%s', 'installed')" % module)
cr.commit()
# ----------------------------------------------------- #
# add some fields (which cannot be added automatically) #
# ----------------------------------------------------- #
for line in (
"ALTER TABLE ir_module_module ADD demo BOOLEAN DEFAULT False",
"delete from ir_values where value like '%,False'",
"""UPDATE ir_ui_view set arch='<?xml version="1.0"?><tree string="Menu" toolbar="1"><field icon="icon" name="name"/></tree>' where name='ir.ui.menu.tree' and type='tree' and field_parent='child_id'""",
):
cr.execute(line)
cr.commit()
cr.close()

View File

@ -88,4 +88,11 @@ if res[0]['typname'] != 'float':
cr.execute(line)
cr.commit()
# ----------------------------- #
# drop constraint on ir_ui_view #
# ----------------------------- #
cr.execute('ALTER TABLE ir_ui_view DROP CONSTRAINT ir_ui_view_type')
cr.commit()
cr.close