[FIX] website_mail_group: restore missing snippet icon
[odoo/odoo.git] / history / migrate / 3.4.0-4.0.0 / pre-tiny.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 __author__ = 'Gaetan de Menten, <ged@tiny.be>'
23 __version__ = '0.1.0'
24
25 import psycopg
26 import optparse
27 import ConfigParser
28
29 # -----
30
31 parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
32
33 parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
34
35 group = optparse.OptionGroup(parser, "Database related options")
36 group.add_option("--db_host", dest="db_host", help="specify the database host") 
37 group.add_option("--db_port", dest="db_port", help="specify the database port") 
38 group.add_option("-d", "--database", dest="db_name", help="specify the database name")
39 group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
40 group.add_option("-w", "--db_password", dest="db_password", help="specify the database password") 
41 parser.add_option_group(group)
42
43 options = optparse.Values()
44 options.db_name = 'terp' # default value
45 parser.parse_args(values=options)
46
47 if hasattr(options, 'config'):
48     configparser = ConfigParser.ConfigParser()
49     configparser.read([options.config])
50     for name, value in configparser.items('options'):
51         if not (hasattr(options, name) and getattr(options, name)):
52             if value in ('true', 'True'):
53                 value = True
54             if value in ('false', 'False'):
55                 value = False
56             setattr(options, name, value)
57
58 # -----
59
60 host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
61 port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
62 name = "dbname=%s" % options.db_name
63 user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
64 password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
65
66 db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
67 cr = db.cursor()
68
69 # ------------------------- #
70 # change some columns types #
71 # ------------------------- #
72
73 def change_column(cr, table, column, new_type, copy):
74     commands = [
75         "ALTER TABLE %s RENAME COLUMN %s TO temp_column" % (table, column),
76         "ALTER TABLE %s ADD COLUMN %s %s" % (table, column, new_type),
77         "ALTER TABLE %s DROP COLUMN temp_column" % table
78     ]
79     if copy:
80         commands.insert(
81             2, 
82             "UPDATE %s SET %s=temp_column::%s" % (table, column, new_type))
83
84     for command in commands:
85         cr.execute(command)
86
87 #change_column(cr, 'crm_case', 'date_closed', 'timestamp', True)
88 cr.commit()
89
90 # -------------------- #
91 # add module if needed #
92 # -------------------- #
93
94 cr.execute("SELECT name FROM ir_module_module")
95 if not cr.rowcount:
96     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',
97 'account_followup',
98 'account',
99 'audittrail',
100 'base_partner_relation',
101 'crm',
102 'delivery',
103 'edi',
104 'hr_evaluation',
105 'hr_expense',
106 'hr',
107 'hr_timesheet_invoice',
108 'hr_timesheet_project',
109 'hr_timesheet',
110 'l10n_simple',
111 'marketing',
112 'mrp',
113 'network',
114 'product',
115 'project',
116 'purchase',
117 'report_crm',
118 'report_project',
119 'report_purchase',
120 'report_sale',
121 'sale_crm',
122 'sale',
123 'sandwich',
124 'scrum',
125 'stock']):
126         cr.execute("INSERT INTO ir_module_module (name, state) VALUES ('%s', 'installed')" % module)
127     cr.commit()
128
129
130 # ----------------------------------------------------- #
131 # add some fields (which cannot be added automatically) #
132 # ----------------------------------------------------- #
133
134 for line in (
135         "ALTER TABLE ir_module_module ADD demo BOOLEAN DEFAULT False",
136         "delete from ir_values where value like '%,False'",
137         """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'""",
138     ):
139     cr.execute(line)
140
141 cr.commit()
142 cr.close()
143
144 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
145