chore(dev): add lab migration and run scripts
This commit is contained in:
parent
0a5c111336
commit
0dc64c7638
3 changed files with 60 additions and 17 deletions
|
|
@ -181,5 +181,19 @@ db-seed: ## Peuple la base de données avec des données de test
|
|||
@echo "$(GREEN)🌱 Peuplement de la base de données...$(NC)"
|
||||
@echo "$(YELLOW)⚠️ Seeding non implémenté$(NC)"
|
||||
|
||||
# Lab Environment
|
||||
migrate-lab: ## Applique les migrations en environnement Lab
|
||||
@echo "$(GREEN)🧪 Migrating Lab Database...$(NC)"
|
||||
@./scripts/apply_migrations_lab.sh
|
||||
|
||||
run-lab: build ## Lance l'application en mode Lab (dégradé sans Redis/RabbitMQ bloquant)
|
||||
@echo "$(GREEN)🧪 Running Lab Server...$(NC)"
|
||||
@export DATABASE_URL=$${VEZA_LAB_DSN:-postgres://veza:veza_password@localhost:5432/veza_lab?sslmode=disable} && \
|
||||
export APP_ENV=development && \
|
||||
export JWT_SECRET=lab-insecure-secret-key-must-be-32-chars-long && \
|
||||
export REDIS_URL=redis://localhost:6379/0 && \
|
||||
export RABBITMQ_ENABLE=false && \
|
||||
./bin/$(BINARY_NAME)
|
||||
|
||||
# Par défaut
|
||||
.DEFAULT_GOAL := help
|
||||
|
|
|
|||
|
|
@ -13,17 +13,28 @@ func main() {
|
|||
logger, _ := zap.NewProduction()
|
||||
|
||||
// Override config from env
|
||||
// SECURITY: DB_PASSWORD is required - no default value to prevent security issues
|
||||
dbPassword := getEnvRequired("DB_PASSWORD")
|
||||
cfg := &database.Config{
|
||||
Host: getEnv("DB_HOST", "localhost"),
|
||||
Port: getEnv("DB_PORT", "5432"),
|
||||
Username: getEnv("DB_USER", "veza"),
|
||||
Password: dbPassword,
|
||||
Database: getEnv("DB_NAME", "veza"),
|
||||
SSLMode: "disable",
|
||||
MaxRetries: 5,
|
||||
RetryInterval: 2 * time.Second,
|
||||
// Override config from env
|
||||
var cfg *database.Config
|
||||
|
||||
if dbURL := os.Getenv("DATABASE_URL"); dbURL != "" {
|
||||
cfg = &database.Config{
|
||||
URL: dbURL,
|
||||
MaxRetries: 5,
|
||||
RetryInterval: 2 * time.Second,
|
||||
}
|
||||
} else {
|
||||
// SECURITY: DB_PASSWORD is required - no default value to prevent security issues
|
||||
dbPassword := getEnvRequired("DB_PASSWORD")
|
||||
cfg = &database.Config{
|
||||
Host: getEnv("DB_HOST", "localhost"),
|
||||
Port: getEnv("DB_PORT", "5432"),
|
||||
Username: getEnv("DB_USER", "veza"),
|
||||
Password: dbPassword,
|
||||
Database: getEnv("DB_NAME", "veza"),
|
||||
SSLMode: "disable",
|
||||
MaxRetries: 5,
|
||||
RetryInterval: 2 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
db, err := database.NewDatabaseWithRetry(cfg, logger)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
# scripts/apply_migrations_lab.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
DB_URL="postgres://postgres:veza@localhost:5435/veza_uuid_lab?sslmode=disable"
|
||||
|
||||
for f in migrations/*.sql; do
|
||||
echo "Applying $f"
|
||||
psql "$DB_URL" -f "$f"
|
||||
done
|
||||
# Script for applying migrations in the lab environment
|
||||
# Usage: ./scripts/apply_migrations_lab.sh
|
||||
|
||||
# Définir les variables de couleurs
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}🔧 Setup migration environment...${NC}"
|
||||
|
||||
# Priorité : VEZA_LAB_DSN > DATABASE_URL default
|
||||
if [ -n "$VEZA_LAB_DSN" ]; then
|
||||
export DATABASE_URL="$VEZA_LAB_DSN"
|
||||
echo -e "Using VEZA_LAB_DSN: $DATABASE_URL"
|
||||
elif [ -z "$DATABASE_URL" ]; then
|
||||
# Default lab DSN if nothing set
|
||||
export DATABASE_URL="postgres://veza:veza_password@localhost:5432/veza_lab?sslmode=disable"
|
||||
echo -e "${YELLOW}Warning: No DATABASE_URL set. Using default Lab DSN: $DATABASE_URL${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}📦 Running migrations...${NC}"
|
||||
go run cmd/migrate_tool/main.go
|
||||
|
||||
echo -e "${GREEN}✅ Migrations applied successfully!${NC}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue