-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_file_sqlx.tf
More file actions
36 lines (28 loc) · 926 Bytes
/
local_file_sqlx.tf
File metadata and controls
36 lines (28 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
resource "local_file" "sqlx" {
count = var.disabled > 0 ? 0 : 1
content = <<EOF
#!/usr/bin/env bash
export DIR="$( cd "$( dirname "$${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
[[ $DB == "" ]] && {
export DB="${local.database}"
}
export DATABASE_URL="postgres://${local.root_user}:${local.root_password}@${local.host}:${local.port}/$DB?sslmode=disable"
cd $DIR/../../../
[ ! -d "$(pwd)/migrations/postgres/$DB" ] && {
echo "Folder does not exist: $(pwd)/migrations/postgres/$DB";
exit 1
}
docker run --name sqlx-postgres-cli --network=${local.network_id} --rm -it \
-v $(pwd)/migrations/postgres/$DB:/app/migrations \
-w /app \
-e DATABASE_URL=$DATABASE_URL \
wcrbrm/sqlx-postgres $@
if [[ $1 == "migrate" ]]; then
if [[ $2 == "add" ]]; then
sudo chown -R `whoami`:`whoami` $(pwd)/migrations/postgres/$DB
fi
fi
EOF
filename = "./bin/sqlx.sh"
file_permission = "0777"
}