Add docker
This commit is contained in:
7
services/db/README.md
Normal file
7
services/db/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# ServerCtl Database
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
tern migrate
|
||||
```
|
10
services/db/migrations/001_create_users.sql
Normal file
10
services/db/migrations/001_create_users.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
create table sctl_user
|
||||
(
|
||||
id int GENERATED BY DEFAULT AS IDENTITY primary key,
|
||||
email varchar(320) not null,
|
||||
password_hash varchar(256) not null
|
||||
);
|
||||
|
||||
---- create above / drop below ----
|
||||
|
||||
drop table sctl_user;
|
10
services/db/migrations/002_emails_are_unique_for_user.sql
Normal file
10
services/db/migrations/002_emails_are_unique_for_user.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- Write your migrate up statements here
|
||||
create unique index user_email_unique_index
|
||||
on sctl_user(email);
|
||||
|
||||
---- create above / drop below ----
|
||||
|
||||
drop index user_email_unique_index;
|
||||
|
||||
-- Write your migrate down statements here. If this migration is irreversible
|
||||
-- Then delete the separator line above.
|
14
services/db/migrations/003_add_projects.sql
Normal file
14
services/db/migrations/003_add_projects.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Write your migrate up statements here
|
||||
|
||||
create table sctl_project
|
||||
(
|
||||
id int GENERATED BY DEFAULT AS IDENTITY primary key,
|
||||
data jsonb NOT NULL
|
||||
);
|
||||
|
||||
---- create above / drop below ----
|
||||
|
||||
drop table sctl_project;
|
||||
|
||||
-- Write your migrate down statements here. If this migration is irreversible
|
||||
-- Then delete the separator line above.
|
9
services/db/migrations/Dockerfile
Normal file
9
services/db/migrations/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM golang:1.17-bullseye
|
||||
|
||||
RUN go install github.com/jackc/tern@latest
|
||||
|
||||
COPY . /app/migration/
|
||||
|
||||
WORKDIR /app/migration
|
||||
|
||||
CMD ./wait-for-database.sh
|
34
services/db/migrations/tern.conf
Normal file
34
services/db/migrations/tern.conf
Normal file
@@ -0,0 +1,34 @@
|
||||
[database]
|
||||
# host is required (network host or path to Unix domain socket)
|
||||
host = localhost
|
||||
port = 5432
|
||||
# database is required
|
||||
database = serverctl
|
||||
# user defaults to OS user
|
||||
user = serverctl
|
||||
password = serverctlsecret
|
||||
version_table = public.schema_version
|
||||
#
|
||||
# sslmode generally matches the behavior described in:
|
||||
# http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION
|
||||
#
|
||||
# There are only two modes that most users should use:
|
||||
# prefer - on trusted networks where security is not required
|
||||
# verify-full - require SSL connection
|
||||
sslmode = prefer
|
||||
#
|
||||
# sslrootcert is generally used with sslmode=verify-full
|
||||
# sslrootcert = /path/to/root/ca
|
||||
|
||||
# Proxy the above database connection via SSH
|
||||
# [ssh-tunnel]
|
||||
# host =
|
||||
# port = 22
|
||||
# user defaults to OS user
|
||||
# user =
|
||||
# password is not required if using SSH agent authentication
|
||||
# password =
|
||||
|
||||
[data]
|
||||
# Any fields in the data section are available in migration templates
|
||||
prefix = serverctl
|
34
services/db/migrations/tern.docker.conf
Normal file
34
services/db/migrations/tern.docker.conf
Normal file
@@ -0,0 +1,34 @@
|
||||
[database]
|
||||
# host is required (network host or path to Unix domain socket)
|
||||
host = db
|
||||
port = 5432
|
||||
# database is required
|
||||
database = serverctl
|
||||
# user defaults to OS user
|
||||
user = serverctl
|
||||
password = serverctlsecret
|
||||
version_table = public.schema_version
|
||||
#
|
||||
# sslmode generally matches the behavior described in:
|
||||
# http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION
|
||||
#
|
||||
# There are only two modes that most users should use:
|
||||
# prefer - on trusted networks where security is not required
|
||||
# verify-full - require SSL connection
|
||||
sslmode = prefer
|
||||
#
|
||||
# sslrootcert is generally used with sslmode=verify-full
|
||||
# sslrootcert = /path/to/root/ca
|
||||
|
||||
# Proxy the above database connection via SSH
|
||||
# [ssh-tunnel]
|
||||
# host =
|
||||
# port = 22
|
||||
# user defaults to OS user
|
||||
# user =
|
||||
# password is not required if using SSH agent authentication
|
||||
# password =
|
||||
|
||||
[data]
|
||||
# Any fields in the data section are available in migration templates
|
||||
prefix = serverctl
|
13
services/db/migrations/wait-for-database.sh
Executable file
13
services/db/migrations/wait-for-database.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# wait-for-postgres.sh
|
||||
|
||||
set -e
|
||||
|
||||
until tern status -c tern.docker.conf; do
|
||||
>&2 echo "Postgres is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "Postgres is up - executing command"
|
||||
|
||||
tern migrate -c tern.docker.conf
|
Reference in New Issue
Block a user