From: Daniel Hokka Zakrisson Date: Sat, 16 Oct 2010 22:10:25 +0000 (-0400) Subject: Create extensions directory. X-Git-Tag: plcapi-5.0-19~71 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=88cae0b8c15eb7f893682c8b63c845a2fc5969da Create extensions directory. --- diff --git a/extensions/README.txt b/extensions/README.txt new file mode 100644 index 0000000..b75a55e --- /dev/null +++ b/extensions/README.txt @@ -0,0 +1,12 @@ +Create a database extension by creating a tree like follows: + +- /usr/share/plc_api/extensions/-up* +Contains the SQL or script that sets up the extension's database needs. + +- /usr/share/plc_api/extensions/-down* +Contains the SQL or script that removes the extension from the database. + +- /usr/share/plc_api/extensions//migrations/[0-9][0-9][0-9]-{up,down}-* +Migration scripts for the extension. One of the scripts for each version +has to execute +UPDATE plc_db_extensions SET version = WHERE name = '' diff --git a/plc.d/db b/plc.d/db index b2f7c3d..644a3ad 100755 --- a/plc.d/db +++ b/plc.d/db @@ -24,10 +24,10 @@ export PGPORT=$PLC_DB_PORT function extend_db() { shopt -s nullglob - for file in /usr/share/plc_api/extensions/*-up; do - script=${file#*/} - name=${script%-up} - extension=${script##*} + for file in /usr/share/plc_api/extensions/*-up*; do + script=${file##*/} + name=${script%-up*} + extension=${script##*.} version=$(psql -U $PLC_DB_USER --quiet --tuples-only --no-align -c \ "SELECT version FROM plc_db_extensions WHERE name='$name' LIMIT 1" \ $PLC_DB_NAME 2>/dev/null | awk '/^[0-9]+$/ { ver=$1 } END { print ver }') @@ -46,7 +46,7 @@ function extend_db() check fi for file in /usr/share/plc_api/extensions/$name/migrations/[0-9]*-up-*; do - script=${file#*/} + script=${file##*/} index=${script%-up-*} extension=${script##*.} if [ $index -gt $version ] ; then diff --git a/setup.py b/setup.py index b74fb01..f0846cf 100755 --- a/setup.py +++ b/setup.py @@ -22,4 +22,5 @@ setup(py_modules = ['ModPython'], ['migrations/README.txt', 'migrations/extract-views.py'] + glob('migrations/[0-9][0-9][0-9]*')), + ('extensions', ['extensions/README.txt']), ])