-
-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] rename_models: add condition to check version and existence of ir_property table #395
Open
xaviedoanhduy
wants to merge
1
commit into
OCA:master
Choose a base branch
from
xaviedoanhduy:imp-rename_models_add_check_version
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,48 +975,49 @@ def rename_models(cr, model_spec): | |
old, | ||
), | ||
) | ||
logged_query( | ||
cr, | ||
""" | ||
UPDATE ir_property | ||
SET res_id = replace(res_id, %(old_string)s, %(new_string)s) | ||
WHERE res_id like %(old_pattern)s""", | ||
{ | ||
"old_pattern": "%s,%%" % old, | ||
"old_string": "%s," % old, | ||
"new_string": "%s," % new, | ||
}, | ||
) | ||
# Handle properties that reference to this model | ||
logged_query( | ||
cr, | ||
"SELECT id FROM ir_model_fields " | ||
"WHERE relation = %s AND ttype = 'many2one'", | ||
(old,), | ||
) | ||
field_ids = [x[0] for x in cr.fetchall()] | ||
logged_query( | ||
cr, | ||
"UPDATE ir_model_fields SET relation = %s WHERE relation = %s", | ||
( | ||
new, | ||
old, | ||
), | ||
) | ||
if field_ids: | ||
if version_info[0] < 18 and table_exists(cr, "ir_property"): | ||
logged_query( | ||
cr, | ||
""" | ||
UPDATE ir_property | ||
SET value_reference = replace( | ||
value_reference, %(old_string)s, %(new_string)s) | ||
WHERE value_reference like %(old_pattern)s""", | ||
SET res_id = replace(res_id, %(old_string)s, %(new_string)s) | ||
WHERE res_id like %(old_pattern)s""", | ||
{ | ||
"old_pattern": "%s,%%" % old, | ||
"old_string": "%s," % old, | ||
"new_string": "%s," % new, | ||
}, | ||
) | ||
# Handle properties that reference to this model | ||
logged_query( | ||
cr, | ||
"SELECT id FROM ir_model_fields " | ||
"WHERE relation = %s AND ttype = 'many2one'", | ||
(old,), | ||
) | ||
field_ids = [x[0] for x in cr.fetchall()] | ||
logged_query( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go outside the |
||
cr, | ||
"UPDATE ir_model_fields SET relation = %s WHERE relation = %s", | ||
( | ||
new, | ||
old, | ||
), | ||
) | ||
if field_ids: | ||
logged_query( | ||
cr, | ||
""" | ||
UPDATE ir_property | ||
SET value_reference = replace( | ||
value_reference, %(old_string)s, %(new_string)s) | ||
WHERE value_reference like %(old_pattern)s""", | ||
{ | ||
"old_pattern": "%s,%%" % old, | ||
"old_string": "%s," % old, | ||
"new_string": "%s," % new, | ||
}, | ||
) | ||
# Handle models that reference to this model using reference fields | ||
cr.execute( | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the reason to check if ir_property exists as a table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just denying the case if the
ir_property
table exists and the version is >= 18.0. because in fact if you use a database from 17.0 or earlier to migrate data to version >= 18.0, their_property
table still exists and is just no longer used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that even in version 18 no operations should be performed in the table even if it exists! I would say checking the version is enough because we can rely on the table existing in earlier versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, maybe it's redundant. i will update it in next patch