-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(events): add postgres docker file
- Loading branch information
Showing
14 changed files
with
105 additions
and
22 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,3 @@ | ||
FROM postgres:15 | ||
|
||
COPY migrations/ /docker-entrypoint-initdb.d/ |
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,74 @@ | ||
function usage() { | ||
usage="$(basename "$0") [-h] [-u <USER>] [-c init|migrate|reset] -- administer the filemanager database. | ||
commands: | ||
init initialize the database | ||
migrate migrate the database using files in the migrations directory | ||
reset drop and recreate the database | ||
options: | ||
-h show this help text | ||
-u set the user for the database [default: POSTGRES_USER environment variable or not set] | ||
-c the command for this script to run [default: not set, required]" | ||
|
||
echo "$usage" | ||
} | ||
|
||
function run_command() { | ||
if [[ "$command" == "init" ]]; then | ||
/bin/bash init_database.sh "${args[@]}" | ||
elif [[ "$command" == "migrate" ]]; then | ||
/bin/bash migrate.sh "${args[@]}" | ||
elif [[ "$command" == "reset" ]]; then | ||
/bin/bash reset_database.sh "${args[@]}" | ||
else | ||
printf "unknown command: -%s\n" "$command" >&2 | ||
usage >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
function set_args() { | ||
if [[ -n "${POSTGRES_USER}" ]]; then | ||
echo "Using ${POSTGRES_USER} as the postgres user" | ||
args+=( "--username" ) | ||
args+=( "POSTGRES_USER" ) | ||
else | ||
echo "No user supplied, using default" | ||
fi | ||
} | ||
|
||
args=() | ||
command="" | ||
while getopts ':hu:c:' option; do | ||
case "$option" in | ||
h) | ||
usage | ||
exit | ||
;; | ||
u) | ||
args+=( "--username" ) | ||
args+=( "$OPTARG" ) | ||
;; | ||
c) | ||
command="$OPTARG" | ||
;; | ||
:) | ||
printf "missing argument for -%s\n" "$OPTARG" >&2 | ||
usage >&2 | ||
exit 1 | ||
;; | ||
\?) | ||
printf "invalid option: -%s\n" "$OPTARG" >&2 | ||
usage >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
if [[ ${#args[@]} -eq 0 ]]; then | ||
set_args | ||
fi | ||
|
||
run_command |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
createdb filemanager | ||
createdb "$@" filemanager |
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 |
---|---|---|
@@ -1,16 +1,6 @@ | ||
#!/bin/bash | ||
|
||
args=() | ||
|
||
if [ -z "$1" ] | ||
then | ||
echo "No user supplied, using default" | ||
else | ||
args+=( "-u" ) | ||
args+=( "$1" ) | ||
fi | ||
|
||
find ./migrations -type f -print0 | while IFS= read -r -d $'\0' file; do | ||
echo "Running migration for $file" | ||
psql "${args[@]}" -d filemanager -a -f "$file" | ||
psql "$@" -d filemanager -a -f "$file" | ||
done |
4 changes: 2 additions & 2 deletions
4
lib/workload/stateless/filemanager/database/reset_database.sh
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
|
||
dropdb filemanager | ||
createdb filemanager | ||
dropdb "$@" filemanager | ||
createdb "$@" filemanager |
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,16 @@ | ||
# NOTE: | ||
# If you update image version, make sure to update in docker-compose.ci.yml as well | ||
|
||
version: '3.1' | ||
|
||
services: | ||
db: | ||
build: database | ||
container_name: filemanager_db | ||
restart: always | ||
environment: | ||
- POSTGRES_DATABASE=filemanager | ||
- POSTGRES_USER=filemanager | ||
- POSTGRES_PASSWORD=filemanager | ||
ports: | ||
- "5432:5432" |
2 changes: 1 addition & 1 deletion
2
lib/workload/stateless/filemanager/filemanager/src/database/mod.rs
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod aws; | ||
pub mod s3; | ||
|
||
use crate::error::Error::DbClientError; | ||
use crate::error::Result; | ||
|
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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
lib/workload/stateless/filemanager/filemanager/src/events/mod.rs
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.