Files
Local_Perplexity/Makefile
2026-02-07 12:37:56 +03:00

80 lines
2.6 KiB
Makefile

NAMESPACE ?= templates
PACKAGE := database_migrations
REGISTRY := registry.halfakop.ru
REPOSITORY := $(NAMESPACE)/$(PACKAGE)
PLATFORM ?= --platform=linux/amd64
SOURCE_VERSION ?= $(shell cat VERSION)
IMAGE_NAME_TAGGED := $(REPOSITORY):$(SOURCE_VERSION)
MIGTATIONS_PATH ?= atlas/migrations
SCHEMA_PATH ?= ent/schema
DEV_DB_URL ?= "postgresql://user:pass@localhost:5432/project-dev?sslmode=disable"
DB_URL ?= "postgresql://user:pass@localhost:5432/project?sslmode=disable"
all: help
help:
@printf "\nORM make targets:\n"
@printf " make generate - Generate ent code from schema in %s\n" "$(SCHEMA_PATH)"
@printf " make clean - Remove generated ent code (schema is kept)\n"
@printf " make initial - Clean + generate + create initial migration into %s (uses DEV_DB_URL)\n" "$(MIGTATIONS_PATH)"
@printf " make migration - Generate and diff a new migration into %s (uses DEV_DB_URL)\n" "$(MIGTATIONS_PATH)"
@printf " make apply - Apply migrations to DB_URL\n"
@printf " make build - Build backend migrations image tagged %s\n" "$(IMAGE_NAME_TAGGED)"
@printf " make login - Login to docker registry %s\n" "$(REGISTRY)"
@printf " make push - Push backend migrations image tagged %s to %s\n" "$(IMAGE_NAME_TAGGED)" "$(REGISTRY)"
@printf "\nVariables:\n"
@printf " MIGTATIONS_PATH=%s\n" "$(MIGTATIONS_PATH)"
@printf " SCHEMA_PATH=%s\n" "$(SCHEMA_PATH)"
@printf " DEV_DB_URL=%s\n" "$(DEV_DB_URL)"
@printf " DB_URL=%s\n\n" "$(DB_URL)"
clean:
@echo "Cleaning orm/ent but keep the schema itself"
@find ent -mindepth 1 -maxdepth 1 ! -name 'schema' -exec rm -rf {} \;
@rm -f .DS_Store
generate:
@echo "Generating schema"
@ent generate "./$(SCHEMA_PATH)"
initial: clean generate
@echo "Creating initial migration"
@atlas migrate diff initial \
--dir "file://$(MIGTATIONS_PATH)" \
--to "ent://$(SCHEMA_PATH)" \
--dev-url="$(DEV_DB_URL)"
migration: generate
@echo "Creating new migration"
@atlas migrate diff add_changes \
--dir "file://$(MIGTATIONS_PATH)" \
--to "ent://$(SCHEMA_PATH)" \
--dev-url="$(DEV_DB_URL)"
apply:
@echo "Applying migrations"
@atlas migrate apply \
--dir "file://$(MIGTATIONS_PATH)" \
--url="$(DB_URL)"
build:
DOCKER_BUILDKIT=0 \
docker build $(PLATFORM) --progress=plain --compress \
-t $(IMAGE_NAME_TAGGED) \
-t $(REGISTRY)/$(IMAGE_NAME_TAGGED) \
${DOCKER_OPTS} \
-f Dockerfile .
login:
$(call check-var-defined,DOCKER_USERNAME)
$(call check-var-defined,DOCKER_PASSWORD)
@echo ${DOCKER_PASSWORD} | \
docker login -u ${DOCKER_USERNAME} --password-stdin $(REGISTRY)
push:
docker push $(REGISTRY)/$(IMAGE_NAME_TAGGED)
.PHONY: all help clean generate initial migration apply build login push