Skip to content

Commit ab990d0

Browse files
committed
update sql, upgrade sqlc to 1.15, merge install_tools
1 parent 1252cb3 commit ab990d0

File tree

12 files changed

+222
-152
lines changed

12 files changed

+222
-152
lines changed

bin/build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ SPEC="openapi.yaml"
1515
GEN_OUT_DIR="internal"
1616
PWD="$(pwd)"
1717

18+
x.install-tools() {
19+
set -o errexit -eo pipefail
20+
21+
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
22+
go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.15.0
23+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.2
24+
}
25+
1826
x.fetch-openapi-generator-jar() {
1927
local url="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$GENVERS/openapi-generator-cli-$GENVERS.jar"
2028
echo "$url > openapi-generator-cli.jar"

bin/install_tools

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/scripts/sql-format.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/bash
22

3+
source "${BASH_SOURCE%/*}/../.helpers.sh"
4+
35
set -e
46

5-
REPO_NAME="$(basename "$(git rev-parse --show-toplevel)")"
6-
if [[ $(basename "$PWD") != "$REPO_NAME" ]]; then
7-
echo "Please run this script from the root repo's directory: '$REPO_NAME'"
8-
echo "Current directory: $PWD"
9-
exit 1
10-
fi
7+
ensure_pwd_is_top_level
118

129
SQL_DIRS="internal/services/queries db/migrations"
1310
for slq_dir in $SQL_DIRS; do
@@ -18,5 +15,5 @@ for slq_dir in $SQL_DIRS; do
1815
--keyword-case 1 \
1916
--placeholder "sqlc\\.(arg|narg)\\(:?[^)]*\\)" \
2017
--inplace \
21-
$(find "$slq_dir" -maxdepth 1 -name '*.sql' | tr '\n' ' ')
18+
$(find "$slq_dir" -maxdepth 1 -name '*.sql')
2219
done

db/migrations/20220724110557_first_migration.up.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ create type role as ENUM (
77
);
88

99
create table users (
10-
user_id serial not null,
10+
user_id bigserial not null,
1111
username text not null,
1212
email text not null,
1313
first_name text,
1414
last_name text,
1515
role role default 'user' not null,
1616
is_verified boolean default 'False' not null,
1717
salt text not null,
18-
password TEXT not null,
18+
password text not null,
1919
is_active boolean default 'True' not null,
2020
is_superuser boolean default 'False' not null,
2121
created_at timestamp without time zone default current_timestamp not null,
@@ -26,22 +26,22 @@ create table users (
2626
);
2727

2828
create table pets (
29-
pet_id serial not null,
29+
pet_id bigserial not null,
3030
color text,
3131
metadata jsonb,
3232
primary key (pet_id),
3333
foreign key (animal_id) references animals (animal_id) on delete cascade
3434
);
3535

3636
create table animals (
37-
animal_id serial not null,
37+
animal_id bigserial not null,
3838
name text not null,
3939
primary key (animal_id),
4040
unique (name)
4141
);
4242

4343
create table pet_tags (
44-
pet_tag_id serial not null,
44+
pet_tag_id bigserial not null,
4545
name text not null,
4646
primary key (pet_tag_id),
4747
unique (name)

db/postgresql.conf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
shared_buffers = 4232MB # min 128kB
2+
effective_cache_size = 5232MB # min 128kB better chance of index-only scans
3+
work_mem = 32MB
4+
maintenance_work_mem = 532MB
5+
checkpoint_completion_target = 0.9
6+
shared_preload_libraries = 'pg_stat_statements'
7+
pg_stat_statements.track = all
8+
jit = off
9+
random_page_cost = 1.1
10+
111
# -----------------------------
212
# PostgreSQL configuration file
313
# -----------------------------
@@ -31,7 +41,6 @@
3141
# TB = terabytes h = hours
3242
# d = days
3343

34-
3544
#------------------------------------------------------------------------------
3645
# FILE LOCATIONS
3746
#------------------------------------------------------------------------------
@@ -103,16 +112,6 @@ listen_addresses = '*'
103112
# RESOURCE USAGE (except WAL)
104113
#------------------------------------------------------------------------------
105114
# - Memory -
106-
shared_buffers = 4232MB # min 128kB
107-
effective_cache_size = 5232MB # min 128kB better chance of index-only scans
108-
work_mem = 32MB
109-
maintenance_work_mem = 532MB
110-
checkpoint_completion_target = 0.9
111-
shared_preload_libraries = 'pg_stat_statements'
112-
pg_stat_statements.track = all
113-
jit = off
114-
115-
116115
# (change requires restart)
117116
#huge_pages = try # on, off, or try
118117
# (change requires restart)

internal/services/gen/animals.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/services/gen/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/services/gen/models.go

Lines changed: 63 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/services/gen/querier.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)