Merge lp:~zaber/openupgrade-addons/directory-parent into lp:openupgrade-addons/6.0

Proposed by Don Kirkby
Status: Rejected
Rejected by: Stefan Rijnhart (Opener)
Proposed branch: lp:~zaber/openupgrade-addons/directory-parent
Merge into: lp:openupgrade-addons/6.0
Diff against target: 84 lines (+75/-0)
2 files modified
document/migrations/6.0.2.1/post-migration.py (+37/-0)
document/migrations/6.0.2.1/pre-migration.py (+38/-0)
To merge this branch: bzr merge lp:~zaber/openupgrade-addons/directory-parent
Reviewer Review Type Date Requested Status
Stefan Rijnhart (Opener) Disapprove
Review via email: mp+115443@code.launchpad.net

Description of the change

Fixes bug 1025896 by manually adding the storage_id column to document_directory.

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Don,

thanks for suggesting a solution to the issue. As I have explained in the issue report, we prefer to assist the database administrator in filling in these required values over filling in a random value.

Best regards,
Stefan.

review: Disapprove

Unmerged revisions

4784. By Don Kirkby

[FIX] Work around new parent constraint on document directories.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'document/migrations/6.0.2.1/post-migration.py'
2--- document/migrations/6.0.2.1/post-migration.py 1970-01-01 00:00:00 +0000
3+++ document/migrations/6.0.2.1/post-migration.py 2012-07-17 21:38:33 +0000
4@@ -0,0 +1,37 @@
5+# -*- coding: utf-8 -*-
6+##############################################################################
7+#
8+# OpenERP, Open Source Management Solution
9+# This migration script copyright (C) 2012 Therp BV (<http://therp.nl>)
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU Affero General Public License as
13+# published by the Free Software Foundation, either version 3 of the
14+# License, or (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU Affero General Public License for more details.
20+#
21+# You should have received a copy of the GNU Affero General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+from openupgrade import openupgrade
27+
28+@openupgrade.migrate()
29+def migrate(cr, version):
30+ storage_id = openupgrade.find_valid_id(cr, 'document_storage')
31+ cr.execute("""\
32+UPDATE document_directory
33+SET storage_id = %d,
34+ parent_id = NULL
35+WHERE storage_id = -1
36+""" % storage_id)
37+ cr.execute("""\
38+ALTER TABLE document_directory
39+ADD CONSTRAINT document_directory_storage_id_fkey
40+FOREIGN KEY (storage_id) REFERENCES document_storage (id) ON DELETE SET NULL
41+""")
42
43=== added file 'document/migrations/6.0.2.1/pre-migration.py'
44--- document/migrations/6.0.2.1/pre-migration.py 1970-01-01 00:00:00 +0000
45+++ document/migrations/6.0.2.1/pre-migration.py 2012-07-17 21:38:33 +0000
46@@ -0,0 +1,38 @@
47+# -*- coding: utf-8 -*-
48+##############################################################################
49+#
50+# OpenERP, Open Source Management Solution
51+# This migration script copyright (C) 2012 Therp BV (<http://therp.nl>)
52+#
53+# This program is free software: you can redistribute it and/or modify
54+# it under the terms of the GNU Affero General Public License as
55+# published by the Free Software Foundation, either version 3 of the
56+# License, or (at your option) any later version.
57+#
58+# This program is distributed in the hope that it will be useful,
59+# but WITHOUT ANY WARRANTY; without even the implied warranty of
60+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61+# GNU Affero General Public License for more details.
62+#
63+# You should have received a copy of the GNU Affero General Public License
64+# along with this program. If not, see <http://www.gnu.org/licenses/>.
65+#
66+##############################################################################
67+
68+from openupgrade import openupgrade
69+
70+@openupgrade.migrate()
71+def migrate(cr, version):
72+ #It's impossible to add the storage_id and the new constraints at the
73+ #same time, so we have to add the column first with some dummy value and
74+ #no foreign key. It will be properly configured in the post-migration.
75+
76+ cr.execute("""\
77+ALTER TABLE document_directory
78+ADD COLUMN storage_id integer
79+""")
80+ cr.execute("""\
81+UPDATE document_directory
82+SET storage_id = -1
83+WHERE parent_id IS NULL
84+""")

Subscribers

People subscribed via source and target branches