This repository is based on "Let's Go Further" by Alex Edwards. The Goal is to provide a well-structured way to start a Go-backed backend infrastructure.
# Install Docker.
brew install docker
# Run Docker app so that we can access the `docker` command.
# Pull the PostgresSQL image.
docker pull postgres:15.5-alpine
# Check the downloaded image.
docker images
# Install `migrate` command.
brew install golang-migrate
# Check the installed `migrate` command.
migrate --version
Take a look at Makefile
and bootstrap.sh
# See all the available commands.
make help
Creates and runs a Docker container with the name postgres
, using the official
postgres:15.5-alpine
Docker image. The container is started as a background
process (-d
flag) and is mapped to port 5432
of the host machine
(-p 127.0.0.1:5432:5432/tcp
flag), which is the default port for PostgreSQL.
The container is also configured with the environment variables POSTGRES_USER
and POSTGRES_PASSWORD
, which set the default username and password for the
PostgreSQL database. In this case, the username is set to root
and the
password is set to password
.
docker run --name postgres \
-p 127.0.0.1:5432:5432/tcp \
-e POSTGRES_USER=root \
-e POSTGRES_PASSWORD=password \
-d postgres:15.5-alpine
# Interact with a PostgreSQL database running inside a Docker container named
# 'postgres'. Open an interactive terminal (`psql`) as the 'root' user for
# executing SQL commands.
docker exec -it postgres psql -U root
# Try the following query in the shell.
SELECT NOW();
touch .envrc
echo "export GREENLIGHT_DB_DSN=postgres://pengyuc:password@localhost:5432/greenlight?sslmode=disable" >> .envrc
bash bootstrap.sh
While cases and spaces don't make a difference in the SQL engine, except for the size of the raw file, I aim to stay consistent and enhance readability whenever possible, just as in my other projects.
- Use
UpperCase
for table names, which might be slightly different from what's in the book. - Use
lower_snake_case
for column names. - Capitalize the keywords in Postgres.
code --install-extension esbenp.prettier-vscode
code --install-extension foxundermoon.shell-format
code --install-extension golang.go
migrate create -ext sql -dir migrations -seq <new_script_file_name>