39 lines
711 B
Go
39 lines
711 B
Go
package main
|
|
|
|
import (
|
|
"narasi-ahli-be/app/database"
|
|
"narasi-ahli-be/app/database/entity"
|
|
"narasi-ahli-be/migrations"
|
|
|
|
"github.com/rs/zerolog"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
func main() {
|
|
fx.New(
|
|
fx.Provide(database.NewDatabase),
|
|
fx.Provide(func() zerolog.Logger {
|
|
return zerolog.Nop()
|
|
}),
|
|
fx.Invoke(func(db *database.Database) {
|
|
// Run migration
|
|
err := migrations.CreateChatHistoryTables(db)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Also auto-migrate existing entities
|
|
err = db.DB.AutoMigrate(
|
|
&entity.AIChatSessions{},
|
|
&entity.AIChatMessages{},
|
|
&entity.AIChatLogs{},
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
println("Migration completed successfully!")
|
|
}),
|
|
).Run()
|
|
}
|