Scott Baker | 222955a | 2019-03-29 09:56:59 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | set -e |
| 18 | |
| 19 | # to generate a patch: |
| 20 | # pushd $SES_DIR && diff -c xos/synchronizer/models/simpleexampleservice.orig xos/synchronizer/models/simpleexampleservice.xproto > /tmp/migration-test.patch && popd |
| 21 | |
| 22 | export PATCH_DIR=`pwd` |
| 23 | export REPO_DIR=/home/smbaker/projects/opencord/ |
| 24 | export SES_DIR=$REPO_DIR/orchestration/xos-services/simpleexampleservice |
| 25 | export SES_MODELS_DIR=$SES_DIR/xos/synchronizer/models |
| 26 | export SES_MIG_DIR=$SES_DIR/xos/synchronizer/migrations |
| 27 | |
| 28 | if [ ! -f $SES_MODELS_DIR/simpleexampleservice.orig ]; then |
| 29 | cp $SES_MODELS_DIR/simpleexampleservice.xproto $SES_MODELS_DIR/simpleexampleservice.orig |
| 30 | fi |
| 31 | |
| 32 | cd $SES_DIR |
| 33 | |
| 34 | # migration-test1: initial image with no new files |
| 35 | rm -rf $SES_MIG_DIR/*.py |
| 36 | rm -rf $SES_MIG_DIR/*.pyc |
| 37 | xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose |
| 38 | |
| 39 | # In case we're pointing to a migration that's in an xos core that isn't released |
| 40 | sed -i 's/0009_auto_20190313_1442/0002_initial_data/g' $SES_MIG_DIR/0001_initial.py |
| 41 | |
| 42 | docker build -t xosproject/simpleexampleservice-synchronizer:migration-test1 -f Dockerfile.synchronizer . |
| 43 | |
| 44 | # migration-test2: new field added |
| 45 | # required string new_field = 3 [ |
| 46 | # help_text = "New field to test data migration", |
| 47 | # db_index = False, |
| 48 | # default = "new_stuff"]; |
| 49 | |
| 50 | patch -d $SES_DIR -i $PATCH_DIR/migration-test2.patch -p0 -o xos/synchronizer/models/simpleexampleservice.xproto |
| 51 | xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose |
| 52 | docker build -t xosproject/simpleexampleservice-synchronizer:migration-test2 -f Dockerfile.synchronizer . |
| 53 | |
| 54 | # migration-test3: new field renamed |
| 55 | # required string renamed_new_field = 3 [ |
| 56 | # help_text = "New field to test data migration", |
| 57 | # db_index = False, |
| 58 | # default = "renamed_new_stuff"]; |
| 59 | |
| 60 | patch -d $SES_DIR -i $PATCH_DIR/migration-test3.patch -p0 -o xos/synchronizer/models/simpleexampleservice.xproto |
| 61 | xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose |
| 62 | |
| 63 | echo "Generated migration script is likely incorrect -- manually edit and change it to a rename" |
| 64 | echo " migrations.RenameField(model_name='simpleexampleservice', old_name='new_field', new_name='renamed_new_field')," |
| 65 | read -n1 -r -p "Press any key and I will launch an editor..." key |
| 66 | emacs $SES_MIG_DIR/0003*.py |
| 67 | |
| 68 | docker build -t xosproject/simpleexampleservice-synchronizer:migration-test3 -f Dockerfile.synchronizer . |
| 69 | |
| 70 | # migration-test4: revert back to original models |
| 71 | cp $SES_MODELS_DIR/simpleexampleservice.orig $SES_MODELS_DIR/simpleexampleservice.xproto |
| 72 | xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose |
| 73 | docker build -t xosproject/simpleexampleservice-synchronizer:migration-test4 -f Dockerfile.synchronizer . |