Complete GORM to sqlc migration
- Remove GORM dependency, use sqlc for type-safe SQL queries - Update all handlers to use sqlc patterns (context, value types) - Fix N+1 query problem in domain listing with JOIN query - Enable SQL query logging in debug mode (USE_EMBEDDED=false) - Add comprehensive comments for non-Go developers
This commit is contained in:
parent
dad96978e0
commit
c4e3a31b69
9 changed files with 94 additions and 97 deletions
|
|
@ -3,6 +3,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context" // context for cancellation and timeouts
|
||||
"crypto/rand" // cryptographically secure random number generator
|
||||
"flag" // standard library for parsing command-line flags
|
||||
"fmt" // formatted I/O, used here for printing output
|
||||
|
|
@ -90,25 +91,22 @@ func main() {
|
|||
log.Fatalf("Failed to hash password: %v", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Get or create a default domain for the admin user.
|
||||
domains, err := database.GetAllDomains()
|
||||
domains, err := database.GetAllDomains(ctx)
|
||||
if err != nil || len(domains) == 0 {
|
||||
// Create a default domain if none exist.
|
||||
domain, err := database.CreateDomain("localhost")
|
||||
err := database.CreateDomain(ctx, "localhost")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create default domain: %v", err)
|
||||
}
|
||||
if err := database.UpsertAdminUser("admin", hash, domain.ID); err != nil {
|
||||
log.Fatalf("Failed to reset admin password: %v", err)
|
||||
domains, err = database.GetAllDomains(ctx)
|
||||
if err != nil || len(domains) == 0 {
|
||||
log.Fatalf("Failed to get domain: %v", err)
|
||||
}
|
||||
fmt.Printf("Admin password reset successfully.\n")
|
||||
fmt.Printf("Username: admin\n")
|
||||
fmt.Printf("Password: %s\n", password)
|
||||
fmt.Printf("Default domain created: localhost\n")
|
||||
return
|
||||
}
|
||||
// Use the first domain found.
|
||||
if err := database.UpsertAdminUser("admin", hash, domains[0].ID); err != nil {
|
||||
if err := database.UpsertAdminUser(ctx, "admin", hash, domains[0].ID); err != nil {
|
||||
log.Fatalf("Failed to reset admin password: %v", err)
|
||||
}
|
||||
fmt.Printf("Admin password reset successfully.\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue