Merge lp:~therp-nl/banking-addons/6.0interactive-support_v5_migration into lp:~therp-nl/banking-addons/6.0-interactive-matching-and-debit-orders

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 113
Proposed branch: lp:~therp-nl/banking-addons/6.0interactive-support_v5_migration
Merge into: lp:~therp-nl/banking-addons/6.0-interactive-matching-and-debit-orders
Diff against target: 112 lines (+95/-1)
2 files modified
account_banking/__openerp__.py (+1/-1)
account_banking/migrations/0.1.111/pre-move_payment_type.py (+94/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/6.0interactive-support_v5_migration
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp (community) Approve
Therp Pending
Review via email: mp+111744@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Seems fine to me, well done for the neatness and clarity.

About the iteration on dict:
97 + for table in column_spec.keys():

We should avoid to use dict.keys() because it will build a copy of the list of keys before the iteration, while dict.iterkeys() will never build it.

You can even write
  for table in column_spec:
which is a shorthand for column_spec.iterkeys()

Anyway, here there is only a few keys so it won't really change.

It can be merged.

review: Approve
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Is the target branch correct?
As you put Therp in the reviewers, I do not merge until a Therp reviewer has approved the proposal.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Guewen,

thank you for your comments. The target branch was an intrusive rewrite during 6.0. The migration script was developed for the stable branch but it applied equally to this branch.

Merged it myself as you approved it already.

Thanks
Stefan.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_banking/__openerp__.py'
--- account_banking/__openerp__.py 2012-02-01 15:36:09 +0000
+++ account_banking/__openerp__.py 2012-06-24 14:44:19 +0000
@@ -30,7 +30,7 @@
30##############################################################################30##############################################################################
31{31{
32 'name': 'Account Banking',32 'name': 'Account Banking',
33 'version': '0.1.106',33 'version': '0.1.111',
34 'license': 'GPL-3',34 'license': 'GPL-3',
35 'author': 'Banking addons community',35 'author': 'Banking addons community',
36 'website': 'https://launchpad.net/banking-addons',36 'website': 'https://launchpad.net/banking-addons',
3737
=== added directory 'account_banking/migrations/0.1.111'
=== added file 'account_banking/migrations/0.1.111/pre-move_payment_type.py'
--- account_banking/migrations/0.1.111/pre-move_payment_type.py 1970-01-01 00:00:00 +0000
+++ account_banking/migrations/0.1.111/pre-move_payment_type.py 2012-06-24 14:44:19 +0000
@@ -0,0 +1,94 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2011-2012 Therp BV (<http://therp.nl>)
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
22import logging
23logger = logging.getLogger('Migration: account_banking')
24
25# methods from openupgrade. Need a proper python library
26def table_exists(cr, table):
27 """ Check whether a certain table or view exists """
28 cr.execute(
29 'SELECT count(relname) FROM pg_class WHERE relname = %s',
30 (table,))
31 return cr.fetchone()[0] == 1
32
33def rename_models(cr, model_spec):
34 """
35 Rename models. Typically called in the pre script.
36 :param model_spec: a list of tuples (old model name, new model name).
37
38 Use case: if a model changes name, but still implements equivalent
39 functionality you will want to update references in for instance
40 relation fields.
41
42 """
43 for (old, new) in model_spec:
44 logger.info("model %s: renaming to %s",
45 old, new)
46 cr.execute('UPDATE ir_model_fields SET relation = %s '
47 'WHERE relation = %s', (new, old,))
48 cr.execute('UPDATE ir_model_data SET model = %s '
49 'WHERE model = %s', (new, old,))
50
51def rename_tables(cr, table_spec):
52 """
53 Rename tables. Typically called in the pre script.
54 This function also renames the id sequence if it exists and if it is
55 not modified in the same run.
56
57 :param table_spec: a list of tuples (old table name, new table name).
58
59 """
60 # Append id sequences
61 to_rename = [x[0] for x in table_spec]
62 for old, new in list(table_spec):
63 if (table_exists(cr, old + '_id_seq') and
64 old + '_id_seq' not in to_rename):
65 table_spec.append((old + '_id_seq', new + '_id_seq'))
66 for (old, new) in table_spec:
67 logger.info("table %s: renaming to %s",
68 old, new)
69 cr.execute('ALTER TABLE "%s" RENAME TO "%s"' % (old, new,))
70
71def rename_columns(cr, column_spec):
72 """
73 Rename table columns. Typically called in the pre script.
74
75 :param column_spec: a hash with table keys, with lists of tuples as values. \
76 Tuples consist of (old_name, new_name).
77
78 """
79 for table in column_spec.keys():
80 for (old, new) in column_spec[table]:
81 logger.info("table %s, column %s: renaming to %s",
82 table, old, new)
83 cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (table, old, new,))
84
85def migrate(cr, version):
86 """
87 Preserve references to Payment Type resources after renaming to
88 Payment Mode Type
89 """
90 if version and version.startswith('5.0.'):
91 rename_models(cr, [['payment.type', 'payment.mode.type']])
92 rename_tables(cr, [['payment_type', 'payment_mode_type']])
93 rename_columns(cr, {'account_bank_statement_line': [
94 ('reconcile_id', 'legacy_bank_statement_reconcile_id')]})

Subscribers

People subscribed via source and target branches

to all changes: