Skip to content

Commit

Permalink
Adds migrations to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan51203 committed Dec 23, 2024
1 parent 87a7bff commit df29f28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ GOIMPORTS := $(GOPATH_BIN)/goimports
GO_PACKAGES = $(shell go list ./... | grep -v vendor)
PACKAGE_BASE := github.com/sdslabs/nymeria

DB_HOST = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'host:' | sed -n 's/.*host: *"\?\([^"]*\)"\?/\1/p')
DB_PORT = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'port:' | sed -n 's/.*port: *"\?\([^"]*\)"\?/\1/p')
DB_USER = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'user:' | sed -n 's/.*user: *"\?\([^"]*\)"\?/\1/p')
DB_PASS = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'password:' | sed -n 's/.*password: *"\?\([^"]*\)"\?/\1/p')
DB_NAME = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'db_name:' | sed -n 's/.*db_name: *"\?\([^"]*\)"\?/\1/p')

UP_MIGRATION_FILE = db/migrations/000001_init_schema.up.sql
DOWN_MIGRATION_FILE = db/migrations/000001_init_schema.down.sql

.PHONY: help vendor build run dev lint format clean

help:
Expand Down Expand Up @@ -73,4 +82,10 @@ install-air:
@curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(GOPATH_BIN)
@echo "Air installed successfully"


apply-migration:
@echo "Applying migration..."
PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(UP_MIGRATION_FILE)

rollback-migration:
@echo "Rolling back migration..."
PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(DOWN_MIGRATION_FILE)
2 changes: 1 addition & 1 deletion db/migrations/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ CREATE TABLE IF NOT EXISTS application (
ORGANIZATION VARCHAR(255),
CREATED_AT TIMESTAMP,
CLIENT_KEY VARCHAR(255),
CLIENT_SECRET TEXT,
CLIENT_SECRET TEXT
);

0 comments on commit df29f28

Please sign in to comment.