Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap us over to use our fork of sqlboiler-crdb #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DOCKER_IMAGE := "ghcr.io/metal-toolbox/fleetdb"
PROJECT_NAME := fleetdb
REPO := "https://github.com/metal-toolbox/fleetdb.git"
SQLBOILER := v4.15.0
SQLBOILER_DRIVER := v4.0.0

## run all tests
test: | unit-test integration-test
Expand Down Expand Up @@ -66,14 +67,21 @@ docker-down:
docker-clean:
@docker-compose -f quickstart.yml down --volumes

## start if not started, and wait for database to be live
docker-up-and-wait:
@cockroach sql --insecure -e "select 1" > /dev/null 2>&1 || (echo "Attempting to start server..." && docker-compose -f quickstart.yml up -d crdb)
@for i in 5 4 3 2 1; do \
cockroach sql --insecure -e "select 1" > /dev/null 2>&1 && break || (echo "Waiting for cockroach server to be live. $$i retries remaining..." && sleep 1); \
done

## setup devel database
dev-database: | vendor
@cockroach sql --insecure -e "drop database if exists fleetdb"
@cockroach sql --insecure -e "create database fleetdb"
@FLEETDB_CRDB_URI="${DEV_DB}" go run main.go migrate up

## setup test database
test-database: | vendor
test-database: | vendor docker-up-and-wait
@cockroach sql --insecure -e "drop database if exists fleetdb_test"
@cockroach sql --insecure -e "create database fleetdb_test"
@FLEETDB_CRDB_URI="${TEST_DB}" go run main.go migrate up
Expand All @@ -87,13 +95,12 @@ fresh-test: clean

## install sqlboiler
install-sqlboiler:
go install github.com/volatiletech/sqlboiler/v4@${SQLBOILER}
@go install github.com/volatiletech/sqlboiler/v4@${SQLBOILER}
@go install github.com/metal-toolbox/sqlboiler-crdb-fleetdb/v4@${SQLBOILER_DRIVER}

## boil sql
boil: install-sqlboiler
make docker-up
make test-database
sqlboiler crdb --add-soft-deletes
boil: install-sqlboiler test-database
@sqlboiler crdb-fleetdb --add-soft-deletes

## log into database
psql:
Expand Down
20 changes: 10 additions & 10 deletions internal/models/crdb_main_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqlboiler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ wipe = true
pkgname = "models"
output = "internal/models"

[crdb]
[crdb-fleetdb]
dbname = "fleetdb_test"
host = "localhost"
port = 26257
Expand Down
Loading