backend-service/internal/cli/migrate.go
ats-tech25 488be7b8ef feat(project): Initialize project structure and core components
- Add initial project scaffolding with Go module and project structure
- Create server and CLI entry points for application
- Implement Makefile with development and build commands
- Add `.env.example` with comprehensive configuration template
- Set up README.md with project documentation and setup instructions
- Configure basic dependencies for server, database, and CLI tools
- Establish internal package structure for models, services, and handlers
- Add initial configuration and environment management
- Prepare for HTTP server, CLI, and database integration
2025-11-05 15:06:07 +00:00

50 lines
1.0 KiB
Go

package cli
import (
"log"
"attune-heart-therapy/internal/config"
"attune-heart-therapy/internal/database"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
)
var migrateCmd = &cobra.Command{
Use: "migrate",
Short: "Run database migrations",
Long: "Run database migrations to create or update database schema",
Run: runMigrate,
}
func runMigrate(cmd *cobra.Command, args []string) {
// Load environment variables
if err := godotenv.Load(); err != nil {
log.Println("No .env file found, using system environment variables")
}
// Load configuration
cfg, err := config.Load()
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
// Initialize database connection
db, err := database.New(cfg)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
defer db.Close()
// Run migrations
if err := db.Migrate(); err != nil {
log.Fatalf("Failed to run migrations: %v", err)
}
log.Println("Database migrations completed successfully")
}
func init() {
rootCmd.AddCommand(migrateCmd)
}