Skip to content

Commit

Permalink
Merge pull request #10 from Nuxify/feature/golang-migrate
Browse files Browse the repository at this point in the history
feat: go-migrate support
  • Loading branch information
kabaluyot authored Jul 10, 2024
2 parents 207746e + 71fc264 commit b621ce1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 57 deletions.
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
include .env

# set default shell
SHELL = bash -e -o pipefail

# variables
VERSION ?= $(shell cat ./VERSION)

now=$(shell date +"%Y%m%d%H%M%S")

default: run

.PHONY: install
Expand Down Expand Up @@ -36,5 +33,18 @@ up:
docker compose down
docker compose up -d --build

.PHONY: schema
schema:
mkdir -p db/migration
migrate create -ext sql -dir db/migration -seq ${NAME}

.PHONY: migrate-up
migrate-up:
migrate -path db/migration/ -database "mysql://${DB_USERNAME}:${DB_PASSWORD}@tcp(${DB_HOST}:${DB_PORT})/${DB_DATABASE}" -verbose up ${STEPS}

.PHONY: migrate-down
migrate-down:
migrate -path db/migration/ -database "mysql://${DB_USERNAME}:${DB_PASSWORD}@tcp(${DB_HOST}:${DB_PORT})/${DB_DATABASE}" -verbose down ${STEPS}

proto-record:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative module/record/interfaces/http/grpc/pb/record.proto
66 changes: 57 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Gomora

A progressive framework-agnostic API template following CLEAN architecture and SOLID principles. DDD inspired :)

## Introduction
Expand All @@ -14,35 +15,82 @@ Gomora provides the example for a module-based gRPC and REST server suitable for
## Local Development

Setup the .env file first
- cp .env.example .env

```bash
cp .env.example .env
```

To bootstrap everything, run:
- make

```bash
make
```

The command above will install, build, and run the binary

For manual install:
- make install

```bash
make install
```

For lint:
- make lint

```bash
make lint
```

Just ensure you installed golangci-lint.

To test:
- make test

```bash
make test
```

For manual build:
- make build
- NOTE: the output for this is in bin/

```bash
make build

# The output for this is in bin/
```

## Docker Build

To build, run:
- make run

```bash
make run
```

To run the container:
- make up

```bash
make up
```

## Database Migration

Gomora uses go-migrate (https://github.com/golang-migrate/migrate) to handle migration. Download and change your migrate database command accordingly.

To create a schema, run:

```bash
make schema NAME=<init_schema>
```

To migrate up, run:

```bash
make migrate-up STEPS=<remove STEPS to apply all or specify step number>
```

To migrate down, run:

```bash
make migrate-down STEPS=<remove STEPS to apply all or specify step number>
```

## License

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

1 change: 1 addition & 0 deletions db/migration/000001_init_schema.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS `records`;
7 changes: 7 additions & 0 deletions db/migration/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE
`records` (
`id` varchar(255) NOT NULL,
`data` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
42 changes: 0 additions & 42 deletions db/records.sql

This file was deleted.

0 comments on commit b621ce1

Please sign in to comment.