package main

import (
	"io/ioutil"
	"log"
	"strings"

	"github.com/niangaodev/art-code/config"
)

func main() {
	config.InitDB()
	defer config.CloseDB()

	// Read SQL file
	content, err := ioutil.ReadFile("scripts/create_services_tables.sql")
	if err != nil {
		log.Fatalf("Failed to read SQL file: %v", err)
	}

	requests := strings.Split(string(content), ";")
	for _, request := range requests {
		request = strings.TrimSpace(request)
		if request == "" {
			continue
		}
		_, err := config.DB.Exec(request)
		if err != nil {
			log.Printf("Error executing query: %s\nError: %v", request, err)
		} else {
			log.Println("Executed query successfully")
		}
	}
	log.Println("Services tables migration completed.")
}
