2025-01-10 11:12:03 +00:00
|
|
|
---
|
2024-12-06 14:38:42 +00:00
|
|
|
# https://taskfile.dev
|
|
|
|
|
|
2025-03-04 15:51:03 +00:00
|
|
|
version: "3"
|
2024-12-06 14:38:42 +00:00
|
|
|
|
|
|
|
|
vars:
|
2025-03-20 11:06:41 +00:00
|
|
|
MIGRATIONS: "internal/database/migrations"
|
2025-05-05 09:31:21 +00:00
|
|
|
QUERIES: "internal/database/queries/"
|
|
|
|
|
CONFIG_FILE: "sqlc.yml"
|
2024-12-06 14:38:42 +00:00
|
|
|
|
2025-05-03 01:16:53 +00:00
|
|
|
includes:
|
|
|
|
|
compose:
|
2025-05-05 09:31:21 +00:00
|
|
|
dir: ".."
|
2025-05-03 01:16:53 +00:00
|
|
|
taskfile: local-deployments.yml
|
|
|
|
|
internal: true
|
|
|
|
|
|
2024-12-06 14:38:42 +00:00
|
|
|
tasks:
|
|
|
|
|
generate:
|
2026-05-21 19:40:04 +00:00
|
|
|
desc: "Recreate the generate DB, apply migrations, and run sqlc generate"
|
2025-03-10 11:03:00 +00:00
|
|
|
run: once
|
2024-12-06 14:38:42 +00:00
|
|
|
cmds:
|
2025-05-03 01:16:53 +00:00
|
|
|
- task: compose:up:generate
|
2025-05-08 16:04:45 +00:00
|
|
|
- psql -p ${PGPORT_GENERATE} postgres -c "DROP DATABASE if exists ${PGDATABASE};"
|
|
|
|
|
- psql -p ${PGPORT_GENERATE} postgres -c "CREATE DATABASE ${PGDATABASE};"
|
2025-05-03 01:16:53 +00:00
|
|
|
- migrate -path {{.MIGRATIONS}} -database {{.DB_URI_GENERATE}} up
|
2025-05-05 09:31:21 +00:00
|
|
|
- sqlc generate --file {{.CONFIG_FILE}}
|
2024-12-06 14:38:42 +00:00
|
|
|
lint:
|
2026-05-21 19:40:04 +00:00
|
|
|
desc: "Validate SQL queries with sqlc vet (and sqlcheck on migrations)"
|
2024-12-06 14:38:42 +00:00
|
|
|
cmds:
|
2025-05-03 01:16:53 +00:00
|
|
|
- task: compose:up:generate
|
2025-05-05 09:31:21 +00:00
|
|
|
- sqlc vet --file {{.CONFIG_FILE}}
|
2025-03-17 18:14:15 +00:00
|
|
|
- |
|
|
|
|
|
exit 0
|
2025-05-05 09:31:21 +00:00
|
|
|
for file in {{.MIGRATIONS}}/*.sql; do
|
2025-03-17 18:14:15 +00:00
|
|
|
if [[ -f "$file" ]]; then
|
|
|
|
|
sqlcheck -c -f $file -r 3 # move to 1
|
|
|
|
|
fi
|
|
|
|
|
done
|
2024-12-06 14:38:42 +00:00
|
|
|
mig:create:
|
2026-05-21 19:40:04 +00:00
|
|
|
desc: "Interactively scaffold a new SQL migration in internal/database/migrations"
|
2024-12-06 14:38:42 +00:00
|
|
|
cmds:
|
|
|
|
|
- |
|
|
|
|
|
read -p "Migration Name: " name
|
|
|
|
|
test -z "$name" && echo "Error: Name is required." && exit 1
|
|
|
|
|
migrate create -ext sql -dir {{.MIGRATIONS}} $name
|