aboutsummaryrefslogtreecommitdiffstats
path: root/postgres
diff options
context:
space:
mode:
Diffstat (limited to 'postgres')
-rw-r--r--postgres/init.sql21
1 files changed, 21 insertions, 0 deletions
diff --git a/postgres/init.sql b/postgres/init.sql
index ea748480..ee1acd8d 100644
--- a/postgres/init.sql
+++ b/postgres/init.sql
@@ -1,3 +1,24 @@
+DO
+$do$
+DECLARE
+ _db TEXT := %s;
+ _user TEXT := %s;
+ _password TEXT := %s;
+BEGIN
+ CREATE EXTENSION IF NOT EXISTS dblink;
+ IF EXISTS (SELECT 1 FROM pg_database WHERE datname = _db) THEN
+ RAISE NOTICE 'Database already exists';
+ ELSE
+ PERFORM dblink_connect(
+ 'host=localhost user=' || _user ||
+ ' password=' || _password ||
+ ' dbname=' || current_database()
+ );
+ PERFORM dblink_exec('CREATE DATABASE ' || _db);
+ END IF;
+END
+$do$;
+
CREATE TABLE IF NOT EXISTS users (
id varchar,
joined_at timestamp,