1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
30 parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
32 parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
34 group = optparse.OptionGroup(parser, "Database related options")
35 group.add_option("--db_host", dest="db_host", help="specify the database host")
36 group.add_option("--db_port", dest="db_port", help="specify the database port")
37 group.add_option("-d", "--database", dest="db_name", help="specify the database name")
38 group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
39 group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
40 parser.add_option_group(group)
42 options = optparse.Values()
43 options.db_name = 'terp' # default value
44 parser.parse_args(values=options)
46 if hasattr(options, 'config'):
47 configparser = ConfigParser.ConfigParser()
48 configparser.read([options.config])
49 for name, value in configparser.items('options'):
50 if not (hasattr(options, name) and getattr(options, name)):
51 if value in ('true', 'True'):
53 if value in ('false', 'False'):
55 setattr(options, name, value)
59 host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
60 port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
61 name = "dbname=%s" % options.db_name
62 user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
63 password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
65 db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
68 # ------------------------------ #
69 # drop not null on ir_attachment #
70 # ------------------------------ #
72 cr.execute('ALTER TABLE ir_attachment \
73 ALTER COLUMN res_model DROP NOT NULL, \
74 ALTER COLUMN res_id DROP NOT NULL')
77 # ---------------------------------- #
78 # change case date_deadline rounding #
79 # ---------------------------------- #
82 c.relname,a.attname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,t.typname,CASE
83 WHEN a.attlen=-1 THEN a.atttypmod-4 ELSE a.attlen END as size FROM pg_class
84 c,pg_attribute a,pg_type t WHERE c.relname='crm_case' AND
85 a.attname='date_deadline' AND c.oid=a.attrelid AND a.atttypid=t.oid""")
87 res = cr.dictfetchall()
88 if res[0]['typname'] != 'timestamp':
90 "ALTER TABLE crm_case RENAME date_deadline TO date_deadline_bak",
91 "ALTER TABLE crm_case ADD date_deadline timestamp",
92 "UPDATE crm_case SET date_deadline = date_deadline_bak",
93 "ALTER TABLE crm_case DROP date_deadline_bak",
98 cr.execute('drop view report_task_user_pipeline_open');
101 cr.execute('alter table ir_model_fields add state varchar(26)')
102 cr.execute('alter table ir_model_fields add select_level varchar(3)')
103 cr.execute('alter table ir_act_wizard add primary key(id)')
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: