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)
	}
}
