--- /dev/null
+Create a database extension by creating a tree like follows:
+
+- /usr/share/plc_api/extensions/<name>-up*
+Contains the SQL or script that sets up the extension's database needs.
+
+- /usr/share/plc_api/extensions/<name>-down*
+Contains the SQL or script that removes the extension from the database.
+
+- /usr/share/plc_api/extensions/<name>/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 = <version> WHERE name = '<name>'
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 }')
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
['migrations/README.txt',
'migrations/extract-views.py']
+ glob('migrations/[0-9][0-9][0-9]*')),
+ ('extensions', ['extensions/README.txt']),
])