Initial commit including .env
This commit is contained in:
38
scratch/inspect_db.go
Normal file
38
scratch/inspect_db.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"doormile/config"
|
||||
"doormile/db"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
_ = godotenv.Load()
|
||||
cfg := config.Load()
|
||||
db.Connect(cfg)
|
||||
|
||||
if db.DB == nil {
|
||||
log.Fatal("DB connection is nil")
|
||||
}
|
||||
|
||||
var tableNames []string
|
||||
err := db.DB.Raw(`
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
ORDER BY table_name;
|
||||
`).Scan(&tableNames).Error
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to query tables: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("--- Tables in DB ---")
|
||||
for _, name := range tableNames {
|
||||
fmt.Println(name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user