Skip to content

Commit 30f26a2

Browse files
committed
trying to fix gobin installation to local bin folder
1 parent 239fbe3 commit 30f26a2

19 files changed

+813
-17
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# not gitignored on purpose
2+
PROJECT_PREFIX=openapi-go
3+
APP_ENV=dev
4+
DB_PORT=5555
5+
POSTGRES_USER=postgres
6+
POSTGRES_PASSWORD=postgres
7+
POSTGRES_SERVER=postgres_db_openapi_dev
8+
POSTGRES_PORT=5432
9+
POSTGRES_DB=postgres

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
PATH_add bin
2+
export GOBIN=$PWD/bin
3+
export PATH=$GOBIN:$PATH

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ issues:
7979
- lll
8080
- godot
8181
- wsl
82+
- gochecknoglobals
8283
# All tests
8384
- path: _test\.go
8485
linters:

.psqlrc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Recommended psql config from Chapter 6: The SQL REPL — An Interactive Setup
2+
3+
-- These set commands are noisy; let's shush 'em.
4+
\set QUIET ON
5+
6+
\set PROMPT1 '%~%x%# '
7+
\x auto
8+
\set ON_ERROR_STOP on
9+
\set ON_ERROR_ROLLBACK interactive
10+
11+
\pset null '¤'
12+
\pset linestyle 'unicode'
13+
\pset unicode_border_linestyle single
14+
\pset unicode_column_linestyle single
15+
\pset unicode_header_linestyle double
16+
\set intervalstyle to 'postgres_verbose';
17+
18+
\setenv LESS '-iMFXSx4R'
19+
-- Take your pick: emacs, nano, vim, or install another
20+
\setenv EDITOR 'vi'
21+
22+
\set QUIET OFF
23+
24+
-- ----------------------
25+
26+
\set QUIET 1
27+
28+
\set PROMPT1 '%M:%[%033[1;31m%]%>%[%033[0m%] %n@%/%R%#%x '
29+
30+
\set PROMPT2 '%M %n@%/%R %# '
31+
32+
\pset null '[null]'
33+
34+
\set COMP_KEYWORD_CASE upper
35+
36+
\timing
37+
38+
\set HISTSIZE 2000
39+
40+
\x auto
41+
42+
\set VERBOSITY verbose
43+
44+
\set QUIET 0
45+
46+
\echo 'Welcome to PostgreSQL! \n'
47+
\echo 'Type :version to see the PostgreSQL version. \n'
48+
\echo 'Type :extensions to see the available extensions. \n'
49+
\echo 'Type \\q to exit. \n'
50+
\set version 'SELECT version();'
51+
\set extensions 'select * from pg_available_extensions;'

bin/build

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PWD="$(pwd)"
1010
x.openapi() {
1111
docker run --rm \
1212
-v "${PWD}/internal:/local" \
13-
-e GO_POST_PROCESS_FILE="/usr/bin/env gofmt -w" \
13+
-e GO_POST_PROCESS_FILE="/usr/bin/env gofmt -w -s" \
1414
-e "GIT_USER_ID=$GIT_USER_ID" \
1515
-e "GIT_REPO_ID=$GIT_REPO_ID" \
1616
openapitools/openapi-generator-cli "$@"
@@ -51,6 +51,16 @@ x.download_swagger_ui() {
5151
mv swagger-ui/* internal/static/swagger-ui/
5252
rm -r swagger-ui
5353
}
54+
55+
x.migrate_up() {
56+
# TODO read .env
57+
migrate -path db/migrations/ -database postgres://postgres:postgres@localhost:5555/postgres?sslmode=disable up
58+
}
59+
60+
x.create_migration() {
61+
migrate create -ext sql -dir db/migrations/ "$*"
62+
}
63+
5464
# --------------------- completion and delegation --------------------
5565
# `complete -C foo foo` > `source <(foo bloated_completion)`
5666

bin/install_tools

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

3+
# https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md
4+
35
set -o errexit -eo pipefail
46

57
cd internal/tools
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# https://github.com/golang-migrate/migrate/issues/179
4+
5+
BASE_BRANCH=$1
6+
7+
OLDEST_NEW_MIGRATION_FILE=$(git diff --name-only origin/"$BASE_BRANCH" --diff-filter=d | grep -m1 db/migrations/)
8+
9+
if [[ -z $OLDEST_NEW_MIGRATION_FILE ]]; then
10+
echo "no new migrations"
11+
exit 0
12+
fi
13+
14+
NEWEST_EXISTING_MIGRATION_FILE=$(git ls-tree -r origin/"$BASE_BRANCH" --name-only | grep db/migrations/ | tail -1)
15+
16+
if [[ -z $NEWEST_EXISTING_MIGRATION_FILE ]]; then
17+
echo "no existing migrations"
18+
exit 0
19+
fi
20+
21+
echo "oldest new migration $OLDEST_NEW_MIGRATION_FILE"
22+
echo "newest existing migration $NEWEST_EXISTING_MIGRATION_FILE"
23+
24+
EXISTING_TIMESTAMP="$(basename "$NEWEST_EXISTING_MIGRATION_FILE" | cut -d '_' -f 1)"
25+
26+
NEW_TIMESTAMP="$(basename "$OLDEST_NEW_MIGRATION_FILE" | cut -d '_' -f 1)"
27+
28+
if [[ $EXISTING_TIMESTAMP -ge $NEW_TIMESTAMP ]]; then
29+
echo "existing migration timestamp is greater than or equal to incoming migration timestamp. please update your migrations timestamp."
30+
exit 1
31+
fi
32+
33+
echo "new migration(s) are safe to merge"
34+
exit 0

cmd/rest-server/main.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* OpenAPI Petstore
3-
*
4-
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
5-
*
6-
* API version: 1.0.0
7-
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
8-
*/
9-
101
package main
112

123
import (

db/migrations/20220724110557_first migration.down.sql

Whitespace-only changes.

db/migrations/20220724110557_first migration.up.sql

Whitespace-only changes.

0 commit comments

Comments
 (0)