Version 10 (modified by 13 years ago) ( diff ) | ,
---|
Table of Contents
Comparson script
Migration Script
All the functions that does the migration have been added to migration_scripts file . migration_scripts file internally calls the functions of migration_helping_methods file too perform the migration . Thus in order to do the migration one just needs to import migration_scripts and call the method corresponding to the migration he wants . Also the user who wishes to do the migration in the db doesn't have to know the internal functioning of migration_script , thus the functions or the methods declared in migration_helping_methods file doesn't concern him.
Methods in migration_scripts file
migrating_to_unique_field
Purpose of the migration
Method of Calling
import migration_scripts import mapping_function migration_scripts.migrating_to_unique_field( web2py_path, app ,field_to_update , changed_table , list_of_tables)
Description of arguments
Argument | Description |
---|---|
web2py_path | The path to the web2py congaing the Eden app (i.e "/home/web2py") |
app | The name of the eden application of whose database needs to be migrated (i.e "eden") |
field_to_update | The name of the field with the unique and notnull property |
changed_table | The name of the original table in which the new unique field id added |
list_of_tables | These contains the list of tables which the changed_tables references |
migration_renaming_field
Purpose of the migration
Renaming a particular table , Thus if any fields point to that table that should be handled too.
Method of Calling
import migration_scripts migration_scripts.migration_renaming_field(web2py_path, app, old_table, old_field_name , new_field_name ,attributes_to_copy)
Description of arguments
Argument | Description |
---|---|
web2py_path | The path to the web2py congaing the Eden app (i.e "/home/web2py") |
app | The name of the eden application of whose database needs to be migrated (i.e "eden") |
old_table | The name of the table in which the field is renamed |
old_field_name | The name of the original field before renaming |
new_field_name | The name of the field after renaming |
attributes_to_copy | The list of attributes which needs to be copied from the old_field to the new_field (needed only in sqlite) |
migration_renaming_table
Purpose of the migration
Renaming a particular field , while keeping the other properties of the field same. Also if there are some index on that table that should be recreated and other constraints should remain unchanged too.
Method of Calling
import migration_scripts migration_scripts.migration_renaming_table(web2py_path, app ,old_table_name,new_table_name)
Description of arguments
Argument | Description |
---|---|
web2py_path | The path to the web2py congaing the Eden app (i.e "/home/web2py") |
app | The name of the eden application of whose database needs to be migrated (i.e "eden") |
old_table_name | The name of the original table before renaming |
new_table_name | The name of the table after renaming |
list_field_to_reference
Purpose of the migration
Some fields that have types like list:integer or list:reference or list:string. These types encode multiple values into one string field. What's in the field looks something like this: "|5|100|23|" -- it has values separated by vertical bars. This is an official Web2py type, and typically Web2py handles packing and unpacking these fields:
Sometimes people find they need to pull those values out into a separate resource. There are various reasons they might want to do this, e.g. they might find they need more than one item of information, so instead of a single value, which might be easy to pack into a list, they want instead to have a separate table in which they can have multiple columns, and join that to the original table. To start with, they make a new table with a column for the values they'll get from the list field, and maybe some empty columns to be filled in later. That new table has a foreign key reference back to the original table. Then for each value in the list field for each record in the original table, they create one record in the new table that points back to the original record.
Example of the migration
http://pastebin.ubuntu.com/1142568/
Method of Calling
import migration_scripts migration_scripts.list_field_to_reference(web2py_path,app,new_table_name , new_list_field , list_field_name , old_table_id_field , old_table)
Description of arguments
Argument | Description |
---|---|
web2py_path | The path to the web2py congaing the Eden app (i.e "/home/web2py") |
app | The name of the eden application of whose database needs to be migrated (i.e "eden") |
new_table_name | The name of the new table to which the list field needs to migrated |
new_list_field | The name of the field in the new table which will hold the content of the list field |
list_field_name | The name of the list field in the original table |
old_table_id_field | The name of the id field in the original table |
old_table | The name of the original table |