-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a DB Docker container and a Makefile (#25)
* root: add Makefile and docker-compose.yml * e2e: change the MySQL host and DB credentials * scripts: add a script to migrate the DB
- Loading branch information
Patryk Kalinowski
authored
Mar 3, 2021
1 parent
baf692f
commit 74dcbb5
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
IS_CI ?= 0 | ||
|
||
DOCKER_COMPOSE_CMD := docker-compose | ||
GO_CMD := go | ||
GO_TEST_CMD := $(GO_CMD) test ./... | ||
GO_RUN_CMD := $(GO_CMD) run | ||
|
||
.PHONY: test | ||
test: db-up | ||
@$(GO_TEST_CMD) | ||
|
||
.PHONY: db-up | ||
db-up: # Start the DB server | ||
ifeq ($(IS_CI), 0) | ||
@$(DOCKER_COMPOSE_CMD) up -d database | ||
endif | ||
|
||
.PHONY: down | ||
down: | ||
@$(DOCKER_COMPOSE_CMD) down | ||
|
||
.PHONY: db-migrate | ||
db-migrate: db-up | ||
@$(GO_RUN_CMD) scripts/migrate.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
database: | ||
image: mysql:8.0.21 | ||
command: --default-authentication-plugin=mysql_native_password | ||
ports: | ||
- '33060:3306' | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=terracost | ||
- MYSQL_DATABASE=terracost_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"log" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
|
||
"github.com/cycloidio/terracost/mysql" | ||
) | ||
|
||
func main() { | ||
db, err := sql.Open("mysql", "root:terracost@tcp(localhost:33060)/terracost_test?multiStatements=true") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := mysql.Migrate(context.Background(), db, "_migrations"); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("Migrated successfully!") | ||
} |