Skip to content

Commit

Permalink
add schemas to postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
steph-koopmanschap committed Jun 22, 2023
1 parent 82bfc6c commit 95ce487
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .env/.local/.postgres/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# POSTGRES DB
PG_PORT=5432
PG_HOST=jasma-pg-db
POSTGRES_DB=postgres
POSTGRES_DB=jasma
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
34 changes: 34 additions & 0 deletions compose/local/postgresql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Check if the version file exists
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'jasma') THEN
-- The database should only be created on the first run / build of postgresql.
-- Create the jasma database
CREATE DATABASE jasma
WITH
OWNER = postgres
TEMPLATE = template0
ENCODING = 'UTF8'
LC_COLLATE = 'C'
LC_CTYPE = 'C'
TABLESPACE = pg_default
CONNECTION LIMIT = -1
IS_TEMPLATE = False;

COMMENT ON DATABASE jasma
IS 'Primary PS-SQL Database of JASMA';

-- Connect to the jasma database
\c jasma;

-- Create the app schema
CREATE SCHEMA app;

-- Create the analytics schema
CREATE SCHEMA analytics;

-- Create the version file indicating the initialization is done
CREATE TABLE IF NOT EXISTS init_version (version INT);
INSERT INTO init_version (version) VALUES (1);
END IF;
END $$;
3 changes: 2 additions & 1 deletion docker-compose-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ services:
networks:
- jasma-network-dev
volumes:
- jasma-storage-dev:/var/lib/postgresql/data #Check that this works
- jasma-storage-dev:/var/lib/postgresql/data #Check that this works
- ./compose/local/postgresql:/docker-entrypoint-initdb.d # Init script for database

# REDIS
jasma-redis-db:
Expand Down

0 comments on commit 95ce487

Please sign in to comment.