-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
81 lines (68 loc) · 2.1 KB
/
justfile
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Set up variables
binary := "lbox"
src := "./main.go"
build-dir := "./bin"
migration-dir := "./db/migrations"
db-dir := "./app.db"
db-type := "postgres" # "sqlite" or "postgres"
# PostgreSQL configurations
pg-user := "arar" # PostgreSQL username
pg-password := "password" # PostgreSQL password
pg-dbname := "arar" # PostgreSQL database name
pg-host := "localhost" # PostgreSQL host
pg-sslmode := "disable" # PostgreSQL SSL mode
db-string := "postgres://" + pg-user + "@" + pg-host + ":5432/" + pg-dbname + "?sslmode=" + pg-sslmode
# Default recipe (optional)
default:
just --list
run:
sqlc generate
templ generate
go run {{src}}
generate:
sqlc generate
templ generate
letterboxd:
go run ./cmd/letterboxd/main.go
film:
go run ./cmd/film/main.go
build:
mkdir -p {{build-dir}}
go build -o {{build-dir}}/{{binary}} {{src}}
clean:
rm -rf {{build-dir}}
reset: db-delete db-create migrate-up
# Create Database
[group('db')]
db-create:
#!/usr/bin/env sh
if [ "{{db-type}}" = "sqlite" ]; then \
touch {{db-dir}}; \
else \
echo "Creating database handled by direnv..."; \
# psql -c "CREATE DATABASE {{pg-dbname}};" -U {{pg-user}}; \
fi
# Deletes all tables in the DB giving you a choice.
[group('db')]
db-delete:
#!/usr/bin/env sh
if [ "{{db-type}}" = "sqlite" ]; then \
rm -f {{db-dir}}; \
else \
echo "Dropping all tables in the PostgreSQL database..."; \
psql -U {{pg-user}} -d {{pg-dbname}} -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"; \
fi; \
[group('db')]
[group('migration')]
migration-create name:
mkdir -p db/migrations
goose -dir {{migration-dir}} create {{name}} sql
[group('db')]
[group('migration')]
migrate-up:
#!/usr/bin/env sh
if [ "{{db-type}}" = "sqlite" ]; then \
GOOSE_DRIVER=sqlite3 GOOSE_DBSTRING={{db-dir}} goose up -dir {{migration-dir}}; \
else \
GOOSE_DRIVER=postgres GOOSE_DBSTRING="{{db-string}}" goose up -dir {{migration-dir}}; \
fi