src/source/howto-rename.rst
branchdoc-dc
changeset 89 d018bfffa7ca
child 97 9783741e866d
equal deleted inserted replaced
88:4b0edce1d63c 89:d018bfffa7ca
       
     1 .. _renamehowto:
       
     2 
       
     3 
       
     4 How to rename classes of existing objects
       
     5 =========================================
       
     6 
       
     7 
       
     8 When you develop new features to PyAMS we sometimes have to rename or modify classes of already stored objects if you do
       
     9 that you will never access yours objects. But PyAMS provides `zodbupdate` script to update easily update the change in ZODB.
       
    10 
       
    11 
       
    12 **1) Include you package in the require resource for you webapp**
       
    13 
       
    14 
       
    15 .. code-block:: python
       
    16 
       
    17     requires = [
       
    18         'mypackage',
       
    19         ...
       
    20     ]
       
    21 
       
    22 **2) Add the Entry points**
       
    23 
       
    24 
       
    25 In the `setup.py` file add 'zodbupdate' params into entry_points where is store zodbupdate directives
       
    26 
       
    27 .. code-block:: python
       
    28 
       
    29       entry_points={
       
    30           'zodbupdate': [
       
    31               'renames = mypackage.generations:RENAMED_CLASSES'
       
    32           ]
       
    33       }
       
    34 
       
    35 
       
    36 
       
    37 **3) Create a module named** ``generation`` **with the migration directives**
       
    38 
       
    39 
       
    40 .. code-block:: python
       
    41 
       
    42     RENAMED_CLASSES = {
       
    43         'mypackage.mymodule MyOldClass': 'mypackage.mymodule MyNewClass'
       
    44     }
       
    45 
       
    46 
       
    47 **4) Run the commands** ``buildout`` .
       
    48 
       
    49 .. code-block:: console
       
    50 
       
    51     $ mypackage/bin/buildout
       
    52     $ webapp/bin/buildout
       
    53 
       
    54 
       
    55 The ``buildout`` command going to install correctly the package and add the new entry_points references in entry_points.txt
       
    56 
       
    57 **5)  Run the commands** ``zodbupdate``
       
    58 
       
    59 To finish run `zodbupdate` to apply the changes describe in `RENAMED_CLASSES`
       
    60 
       
    61 .. code-block:: console
       
    62 
       
    63     $   bin/zodbupdate --config etc/zodbupdate-zeo.conf
       
    64 
       
    65 
       
    66 Where `zodbupdate-zeo.conf` is the configuration file to access to the ZODB.