Commit 1cfbdc69 authored by Sean's avatar Sean 🎨

All schema and bash scripts

parent b419f598
CREATE USER test_app WITH PASSWORD 'pass';
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION test_app;
#!/bin/sh
# Stops and removes the container and also remoes the volume
docker stop cat-postgres-db
docker rm cat-postgres-db
docker volume rm cat-db
echo "No more dockerized cat data"
#!/bin/sh
echo "Setting up postgres db in a docker container with a volume..."
if docker volume ls | grep cat-db > /dev/null
then
echo ' > volume cat-db found'
else
echo ' > creating volume cat-db'
docker volume create cat-db
fi
echo "starting cat-postgres-db in the background with cat-db volume..."
docker run --name cat-postgres-db \
-e POSTGRES_PASSWORD=pass \
-d \
-p 5432:5432 \
-v cat-db:/var/lib/postgresql/data \
postgres:12.1-alpine
echo 'giving postgres a hot minute to boot up...'
sleep 4
echo "creating db user and schema..."
cat pre-schema.sql | docker exec -i cat-postgres-db \
psql -U postgres -f -
echo "loading schema..."
cat schema.sql | docker exec -i cat-postgres-db \
psql -U test_app -d postgres -f -
echo "cat-postgres-db setup on localhost:5432"
CREATE TABLE IF NOT EXISTS test.attributes(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT ''
);
CREATE TABLE IF NOT EXISTS test.breeds(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL DEFAULT ''
);
CREATE TABLE IF NOT EXISTS test.breed_attributes(
attributeId INTEGER NOT NULL DEFAULT 1,
breedId INTEGER NOT NULL DEFAULT 1,
FOREIGN KEY (attributeId) REFERENCES test.attributes,
FOREIGN KEY (breedId) REFERENCES test.breeds
);
CREATE TABLE IF NOT EXISTS test.cats(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL DEFAULT '',
breedId INTEGER NOT NULL DEFAULT 1,
FOREIGN KEY (breedId) REFERENCES test.breeds
);
CREATE TABLE IF NOT EXISTS test.owners(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL DEFAULT '',
age INTEGER NOT NULL DEFAULT 20
);
CREATE TABLE IF NOT EXISTS test.owner_cats(
ownerId INTEGER NOT NULL DEFAULT 1,
catId INTEGER NOT NULL DEFAULT 1,
FOREIGN KEY (ownerId) REFERENCES test.owners,
FOREIGN KEY (catId) REFERENCES test.cats
);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment