Commit 24556301 by mhmdhaekal

migration(initialize): create migration

1 parent 3172c624
DATABASE_URL=
BINDIR := bin ifneq (,$(wildcard .env))
include .env
export
endif
BINDIR := bin
APPS := $(notdir $(wildcard cmd/*)) APPS := $(notdir $(wildcard cmd/*))
BUILD_TARGETS := $(filter-out build clean, $(MAKECMDGOALS)) BUILD_TARGETS := $(filter-out build clean, $(MAKECMDGOALS))
.PHONY: build clean default .PHONY: build clean default
...@@ -48,5 +51,21 @@ test: ...@@ -48,5 +51,21 @@ test:
@echo "Running test" @echo "Running test"
@go test ./... @go test ./...
migrate-postgres:
@if [ -z "$(DATABASE_URL)" ]; then \
echo "Error: DATABASE_URL is not set. Please set it in .env or your environment."; \
exit 1; \
fi; \
echo "Running database migrations with goose using driver $$driver..."; \
goose -dir migration/postgres postgres "$(DATABASE_URL)" up
migrate-postgres-status:
@if [ -z "$(DATABASE_URL)" ]; then \
echo "Error: DATABASE_URL is not set. Please set it in .env or your environment."; \
exit 1; \
fi; \
echo "Running migration status with goose using driver $$driver..."; \
goose -dir migration/postgres postgres "$(DATABASE_URL)" status
%: %:
@: @:
-- +goose Up
-- +goose StatementBegin
CREATE TABLE "user" (
"id" SERIAL PRIMARY KEY,
"IdentityNumber" VARCHAR(255) UNIQUE NOT NULL,
"email" VARCHAR(255) UNIQUE NOT NULL,
"name" VARCHAR(255) NOT NULL,
"is_active" BOOLEAN NOT NULL DEFAULT FALSE,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"deleted_at" TIMESTAMPTZ
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE "user";
-- +goose StatementEnd
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!