Skip to content

Latest commit

 

History

History
309 lines (267 loc) · 14.9 KB

README.md

File metadata and controls

309 lines (267 loc) · 14.9 KB
<title>Field Renaming — OpenUpgrade 15.0 documentation</title> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/sphinx_highlight.js"></script>
<div class="document">
  <div class="documentwrapper">
    <div class="bodywrapper">
      

      <div class="body" role="main">

Field Renaming

From version 14.0 to version 15.0, in the module mail, in the model mail.activity.type the html field default_description has been renamed into default_note.

Analysis

...
---Fields in module 'mail'---
...
mail         / mail.activity.type       / default_description (html)    : DEL
...
mail         / mail.activity.type       / default_note (html)           : NEW

See Full V15 Analysis File.

Source Code Differences

Version 14.0

class MailActivityType(models.Model):
<span class="n">_name</span> <span class="o">=</span> <span class="s1">&#39;mail.activity.type&#39;</span>

<span class="n">default_description</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Html</span><span class="p">(</span>
    <span class="n">string</span><span class="o">=</span><span class="s2">&quot;Default Description&quot;</span><span class="p">,</span>
    <span class="n">translate</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="p">)</span>

See Full V14 Code Source.

Version 15.0

class MailActivityType(models.Model):
<span class="n">_name</span> <span class="o">=</span> <span class="s1">&#39;mail.activity.type&#39;</span>

<span class="n">default_note</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Html</span><span class="p">(</span>
    <span class="n">string</span><span class="o">=</span><span class="s2">&quot;Default Description&quot;</span><span class="p">,</span>
    <span class="n">translate</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="p">)</span>

See Full V15 Code Source.

Result without migration script / Expected Result

V14 table mail_activity_type

id

name

default_description

1

Email

<p>A description</p>

2

Call

3

Meeting

<p>Another description</p>

V15 table mail_activity_type (Without migration script)

id

name

default_note

1

Email

2

Call

3

Meeting

Problem : the data is lost during them migration process, and the new column is empty.

V15 table mail_activity_type (With migration script)

id

name

default_note

1

Email

<p>A description</p>

2

Call

3

Meeting

<p>Another description</p>

Contribution to OpenUpgrade

Update upgrade_analysis_work.txt file

  • Place side by side the two lines that correspond to the change

  • Mention the operation performed, starting with # DONE:

---Fields in module 'mail'---
mail         / mail.activity.type       / default_note (html)           : NEW
mail         / mail.activity.type       / default_description (html)    : DEL
# DONE: pre-migration, rename fields default_description -> default_note

See Full V15 Work Analysis File.

Write migration Script

in the pre-migration.py script add:

from openupgradelib import openupgrade

def _rename_fields(env): openupgrade.rename_fields( env, [ ( "mail.activity.type", "mail_activity_type", "default_description", "default_note", ), ] )

@openupgrade.migrate() def migrate(env, version): _rename_fields(env)

See Full pre migration Script.

      </div>
      
    </div>
  </div>
  <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
    <div class="sphinxsidebarwrapper">

Navigation

<script>document.getElementById('searchbox').style.display = "block"</script>
    </div>
  </div>
  <div class="clearer"></div>
</div>
<div class="footer">
  &copy;2012-2021, Odoo Community Association (OCA) / The OpenUpgrade developers.
  
  |
  Powered by <a href="http://sphinx-doc.org/">Sphinx 5.2.3</a>
  &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
  
  |
  <a href="../_sources/use_cases/field_renaming.rst.txt"
      rel="nofollow">Page source</a>
</div>