diff --git a/README.md b/README.md index 318cd4866..dfd280343 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ make -f docker test ### Setting up a local single node database After starting the Docker image or local PostgreSQL server, you can initiate a local single node database: ```bash -psql -U postgres -h localhost < scripts/sql/setup_single_node_db.psql +DB_NAME=iobeamdb ./scripts/setup-db.sh ``` This will set up a database named `iobeamdb` which can be accessed with: ```bash -psql -U postgres -h localhost -d iobeamdb +psql -U postgres -d iobeamdb ``` #### Creating a table diff --git a/scripts/setup-db.sh b/scripts/setup-db.sh new file mode 100755 index 000000000..b7006d725 --- /dev/null +++ b/scripts/setup-db.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +if [[ -z "$DB_NAME" ]]; then + echo "The DB_NAME must be set" + exit 1 +fi + +# Create data directories for tablespaces tests +psql -U postgres -v ON_ERROR_STOP=1 << EOF +\echo 'Creating database: ${DB_NAME}' +CREATE DATABASE ${DB_NAME}; + +\c ${DB_NAME} +CREATE EXTENSION IF NOT EXISTS iobeamdb CASCADE; + +\o /dev/null +\echo 'Set up database as meta node...' +select setup_meta(); +\echo 'Set up database as data node...' +select setup_main(); + +SELECT add_cluster_user('postgres', NULL); + +\echo 'Adding database iobeam to the single-node cluster...' +SELECT set_meta('${DB_NAME}' :: NAME, 'localhost'); +SELECT add_node('${DB_NAME}' :: NAME, 'localhost'); + +\echo 'Success' +EOF diff --git a/scripts/sql/setup_single_node_db.psql b/scripts/sql/setup_single_node_db.psql deleted file mode 100644 index ed1c91175..000000000 --- a/scripts/sql/setup_single_node_db.psql +++ /dev/null @@ -1,19 +0,0 @@ -\set ON_ERROR_STOP 1 -CREATE DATABASE iobeam; - -\c iobeam -CREATE EXTENSION IF NOT EXISTS iobeamdb CASCADE; - -\o /dev/null -\echo 'Set up database as meta node...' -select setup_meta(); -\echo 'Set up database as data node...' -select setup_main(); - -SELECT add_cluster_user('postgres', NULL); - -\echo 'Adding database iobeam to the single-node cluster...' -SELECT set_meta('iobeam' :: NAME, 'localhost'); -SELECT add_node('iobeam' :: NAME, 'localhost'); - -\echo 'Success'