blob: bd90091a70c4d95fe7b09e8962fabe303be88e5c [file] [log] [blame]
Scott Baker222955a2019-03-29 09:56:59 -07001#!/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
17set -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
22export PATCH_DIR=`pwd`
23export REPO_DIR=/home/smbaker/projects/opencord/
24export SES_DIR=$REPO_DIR/orchestration/xos-services/simpleexampleservice
25export SES_MODELS_DIR=$SES_DIR/xos/synchronizer/models
26export SES_MIG_DIR=$SES_DIR/xos/synchronizer/migrations
27
28if [ ! -f $SES_MODELS_DIR/simpleexampleservice.orig ]; then
29 cp $SES_MODELS_DIR/simpleexampleservice.xproto $SES_MODELS_DIR/simpleexampleservice.orig
30fi
31
32cd $SES_DIR
33
34# migration-test1: initial image with no new files
35rm -rf $SES_MIG_DIR/*.py
36rm -rf $SES_MIG_DIR/*.pyc
37xos-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
40sed -i 's/0009_auto_20190313_1442/0002_initial_data/g' $SES_MIG_DIR/0001_initial.py
41
42docker 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
50patch -d $SES_DIR -i $PATCH_DIR/migration-test2.patch -p0 -o xos/synchronizer/models/simpleexampleservice.xproto
51xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose
52docker 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
60patch -d $SES_DIR -i $PATCH_DIR/migration-test3.patch -p0 -o xos/synchronizer/models/simpleexampleservice.xproto
61xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose
62
63echo "Generated migration script is likely incorrect -- manually edit and change it to a rename"
64echo " migrations.RenameField(model_name='simpleexampleservice', old_name='new_field', new_name='renamed_new_field'),"
65read -n1 -r -p "Press any key and I will launch an editor..." key
66emacs $SES_MIG_DIR/0003*.py
67
68docker build -t xosproject/simpleexampleservice-synchronizer:migration-test3 -f Dockerfile.synchronizer .
69
70# migration-test4: revert back to original models
71cp $SES_MODELS_DIR/simpleexampleservice.orig $SES_MODELS_DIR/simpleexampleservice.xproto
72xos-migrate -r $REPO_DIR -s simpleexampleservice --verbose
73docker build -t xosproject/simpleexampleservice-synchronizer:migration-test4 -f Dockerfile.synchronizer .