[FIX] website_mail_group: restore missing snippet icon
[odoo/odoo.git] / history / migrate / 4.2.0-4.4.0 / pre.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21
22 __version__ = '0.1.0'
23
24 import psycopg
25 import optparse
26 import ConfigParser
27
28 # -----
29
30 parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
31
32 parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
33
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)
41
42 options = optparse.Values()
43 options.db_name = 'terp' # default value
44 parser.parse_args(values=options)
45
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'):
52                 value = True
53             if value in ('false', 'False'):
54                 value = False
55             setattr(options, name, value)
56
57 # -----
58
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 ''
64
65 db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
66 cr = db.cursor()
67
68 # ------------------------------ #
69 # drop not null on ir_attachment #
70 # ------------------------------ #
71
72 cr.execute('ALTER TABLE ir_attachment \
73         ALTER COLUMN res_model DROP NOT NULL, \
74         ALTER COLUMN res_id DROP NOT NULL')
75 cr.commit()
76
77 # ---------------------------------- #
78 # change case date_deadline rounding #
79 # ---------------------------------- #
80
81 cr.execute("""SELECT
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""")
86
87 res = cr.dictfetchall()
88 if res[0]['typname'] != 'timestamp':
89     for line in (
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",
94         ):
95         cr.execute(line)
96 cr.commit()
97
98 cr.execute('drop view report_task_user_pipeline_open');
99 cr.commit()
100
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)')
104 cr.commit()
105
106
107 cr.close()
108
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
110