-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fafbac0
commit 352de5f
Showing
34 changed files
with
157 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 'latest' | ||
services: | ||
postgres-db: | ||
container_name: postgres-db | ||
build: | ||
context: . | ||
dockerfile: docker/Dockerfile-db | ||
environment: | ||
- POSTGRES_USER=admin | ||
- POSTGRES_PASSWORD=notespace | ||
- POSTGRES_DB=notespace | ||
ports: | ||
- 5432:5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM ubuntu:latest | ||
LABEL authors="primu" | ||
|
||
ENTRYPOINT ["top", "-b"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM postgres | ||
|
||
USER postgres | ||
WORKDIR /app | ||
|
||
COPY ./src/sql/create_tables.sql /docker-entrypoint-initdb.d/1_create-schema.sql | ||
|
||
COPY --chown=postgres:postgres ./docker/scripts/wait-for-postgres.sh ./bin/wait-for-postgres.sh | ||
RUN chmod +x ./bin/wait-for-postgres.sh | ||
|
||
EXPOSE 5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
# wait-for-postgres.sh host cmd | ||
|
||
set -e | ||
|
||
host="$1" | ||
shift | ||
cmd="$@" | ||
|
||
>&2 echo "waiting for postgres on $host" | ||
until pg_isready -h $host; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
>&2 echo "Postgres is up - executing command '$cmd'" | ||
exec $cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
begin ; | ||
|
||
-- Delete all rows from the resources table | ||
delete from resource ; | ||
|
||
-- Delete all rows from the workspaces table | ||
delete from workspace ; | ||
|
||
commit ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
begin; | ||
|
||
create extension if not exists "uuid-ossp"; | ||
|
||
create type resource_type as enum ('D', 'F'); | ||
|
||
create table if not exists workspace ( | ||
id uuid primary key default uuid_generate_v4(), | ||
name text not null, | ||
created_at timestamp not null default now(), | ||
updated_at timestamp not null default now() | ||
); | ||
|
||
create table if not exists resource ( | ||
id uuid primary key default uuid_generate_v4(), | ||
workspace uuid not null references workspace(id) on delete cascade, | ||
name text not null, | ||
type resource_type not null, | ||
created_at timestamp not null default now(), | ||
updated_at timestamp not null default now() | ||
); | ||
|
||
create table if not exists resource_child ( | ||
parent uuid not null references resource(id) on delete cascade, | ||
child uuid not null references resource(id) on delete cascade, | ||
primary key (parent, child) | ||
); | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
begin ; | ||
|
||
drop table if exists resources cascade ; | ||
|
||
drop table if exists workspaces cascade ; | ||
|
||
drop type if exists resource_type cascade ; | ||
|
||
commit ; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
begin ; | ||
|
||
-- Create the trigger function | ||
create or replace function delete_resource_on_child_delete() returns trigger as $$ | ||
begin | ||
delete from resource where id = old.child; | ||
return old; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger delete_resource_trigger | ||
after delete on resource_child | ||
for each row execute function delete_resource_on_child_delete(); | ||
|
||
commit ; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { config } from 'dotenv'; | ||
|
||
config(); | ||
|
||
const PG_USER = process.env.PG_USER; | ||
const PG_PASSWORD = process.env.PG_PASSWORD; | ||
const PG_HOST = process.env.PG_HOST; | ||
const PG_PORT = process.env.PG_PORT || '5432'; | ||
const PG_DATABASE = process.env.PG_DATABASE; | ||
|
||
export default { | ||
PG_USER, | ||
PG_PASSWORD, | ||
PG_HOST, | ||
PG_PORT, | ||
PG_DATABASE, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pg from 'pg'; | ||
import dbConfig from './config'; | ||
|
||
const credentials = { | ||
user: dbConfig.PG_USER, | ||
host: dbConfig.PG_HOST, | ||
database: dbConfig.PG_DATABASE, | ||
password: dbConfig.PG_PASSWORD, | ||
port: parseInt(dbConfig.PG_PORT), | ||
}; | ||
|
||
const connect = async () => { | ||
const { Client } = pg; | ||
const client = new Client(credentials); | ||
await client.connect(); | ||
return client; | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters