54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"Rezina-Backend/internal/demoseed"
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
environment := flag.String("environment", "", "Required: development, test, or staging")
|
|
flag.Parse()
|
|
_ = godotenv.Load()
|
|
if err := demoseed.ValidateEnvironment(*environment, os.Getenv("APP_ENV"), os.Getenv("ENVIRONMENT"), os.Getenv("GO_ENV"), os.Getenv("ENV")); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
url := os.Getenv("DB_URL")
|
|
if url == "" {
|
|
fmt.Fprintln(os.Stderr, "DB_URL is required")
|
|
os.Exit(1)
|
|
}
|
|
password := os.Getenv("DEMO_SEED_PASSWORD")
|
|
if password == "" {
|
|
password = demoseed.DefaultPassword
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
conn, err := pgx.Connect(ctx, url)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "Cannot connect to the demo database. Check DB_URL and start PostgreSQL.")
|
|
os.Exit(1)
|
|
}
|
|
defer conn.Close(ctx)
|
|
video := os.Getenv("DEMO_VIDEO_URL")
|
|
if video == "" {
|
|
video = "https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
|
|
}
|
|
if err = demoseed.Run(ctx, conn, password, video); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Demo seed failed:", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println("Makeup artistry demo seed complete: 3 published courses, 6 chapters, 18 lessons, 6 quizzes, 18 questions, and 1 hidden draft course.")
|
|
fmt.Println("Test accounts (password: DEMO_SEED_PASSWORD, or RezinaDemo!2026 when unset):")
|
|
for _, a := range demoseed.Accounts {
|
|
fmt.Printf(" %-36s %-16s %s\n", a.Email, a.Role, a.Audience)
|
|
}
|
|
}
|