//go:build ignore package main import ( "database/sql" "fmt" "log" "os" _ "github.com/lib/pq" ) func main() { // DSN matches the one in connect.go and .env // Built from the environment, not hardcoded. This line used to carry the // production host and password in plaintext, in a file tracked by git — so // the live database credential shipped with every clone. Export DB_HOST, // DB_USER, DB_PASSWORD, DB_NAME and DB_PORT (or source .env) before running. dsn := fmt.Sprintf( "host=%s user=%s password=%s dbname=%s port=%s sslmode=disable", os.Getenv("DB_HOST"), os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD"), os.Getenv("DB_NAME"), os.Getenv("DB_PORT"), ) db, err := sql.Open("postgres", dsn) if err != nil { log.Fatalf("Failed to open DB: %v", err) } defer db.Close() if err := db.Ping(); err != nil { log.Fatalf("Failed to ping DB: %v", err) } fmt.Println("--- Listing Tables in logistics Database ---") rows, err := db.Query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name; `) if err != nil { log.Fatalf("Failed to query tables: %v", err) } defer rows.Close() for rows.Next() { var name string if err := rows.Scan(&name); err != nil { log.Fatalf("Scan failed: %v", err) } fmt.Printf("Table: %s\n", name) } }