Skip to content

Commit

Permalink
Merge pull request #2 from dmvieira/develop
Browse files Browse the repository at this point in the history
now migrate use before and after migrates once
  • Loading branch information
dmvieira committed Aug 31, 2014
2 parents 5b5510e + 5ef9152 commit 5dd38dc
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 9 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project aim is organize and control [web2py](https://github.com/web2py/web2
with version control using version control tags.

So you can assign your versions with tags for some branchs. For example, if you have a dev and a master branch
you can assign `master-migrate` and `dev-migrate` tags and your migrates for dev and master databases will be
you can assign `master-migrate` and `develop-migrate` tags and your migrates for dev and master databases will be
independently controlled.

This is very important if you want a [Continuous Integration](http://en.wikipedia.org/wiki/Continuous_integration)
Expand Down Expand Up @@ -53,9 +53,16 @@ Now just use make command:

`make`

If you want more, you can do these tricks:
* Add to sql foder before migrates sql for eg. prepopulate some table
* Add to sql folder after migrates sql for eg. data migration
* Add python scripts inside migrate.py to run some command after migration using your web2py app model

`sql` folder need scripts using names: `before-BRANCH.sql` and `after-BRANCH.sql` like examples inside folder that use develop and master branchs.

Now your first database migration is working and the TAG is now on your version control!

If some errors occur, database will be backed up but tags are NOT RESTRUCTURED!!
If some errors occur, database will be backed up but tags are NOT RESTRUCTURED and before and after migration scripts are NOT CLEANED!!

For Developers
---------------
Expand Down
28 changes: 23 additions & 5 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ make_migrate(){
#create web2py paths
mkdir $DATABASES $APP_PATH/sessions $APP_PATH/errors || true;

#default do not re send to version control
sendit=0;
echo "making database backup";
rds_backup || exit 10;
echo "executing pre-migrate sqls";
rds_import pre-migrate.sql || true;
if [ -s "sql/before-${BRANCH}.sql" ];
then
rds_import sql/before-${BRANCH}.sql && sendit=1 || exit 1;
fi
echo "making .tables with old db.py and fake_migrate if tag exists";
#if tag dont exists then just make first migrate
if vc_check_tag;
Expand All @@ -46,7 +51,7 @@ then
fi
echo "executing web2py migrate with deploy db.py";
export FAKE_MIGRATE_ENV=0;
#return current web2py folder, branch and commit
#return current web2py folder, branch and version
cd ${WEB2PY};
#just printing status for information
vc_status;
Expand All @@ -57,11 +62,24 @@ vc_status;
cd ${DIR};
make_migrate;
echo "executing pos-migrate sqls";
rds_import pos-migrate.sql || true;
if [ -s "sql/after-${BRANCH}.sql" ];
then
rds_import sql/after-${BRANCH}.sql && sendit=1 || exit 1;
fi
export MIGRATE_ENV=0;
#last modifications with databases
rds_finish;
rds_finish || echo "error cleaning test server, please use finish by hand";
echo "redefining tag"
vc_remove_tag || true;
vc_remove_tag || "error removing tag";
vc_add_tag || echo "error adding tag";
#send to version control again if did before and after migrates
if [ $sendit -eq 1 ];
then
> sql/before-${BRANCH}.sql || echo "error cleaning before migrate";
> sql/after-${BRANCH}.sql || echo "error cleaning after migrate";
#return current web2py folder to send new file
cd ${WEB2PY};
vc_send || echo "error sending again to vc without after and before migrates";
fi

echo "migrate ok!";
File renamed without changes.
File renamed without changes.
Empty file added sql/before-develop.sql
Empty file.
Empty file added sql/before-master.sql
Empty file.
8 changes: 7 additions & 1 deletion version_control/dummy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ vc_remove_tag()
vc_add_tag()
{
echo "adding tag..."
}
}

# send new code to version control
vc_send()
{
echo "sending new code..."
}
11 changes: 10 additions & 1 deletion version_control/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ vc_add_tag()
{
git tag $TAG &&
git push --tags;
}
}

# sending new code to version control
vc_send()
{
git config --global user.email "[email protected]"
git config --global user.name "Test Server"
git commit -am "new code without before and after migrates scripts" &&
git push origin HEAD;
}

0 comments on commit 5dd38dc

Please sign in to comment.