Files
stpweb/backend/services/database.go
T
adamfandClaude Opus 5 894c158afd
Deploy with Docker Compose / deploy (push) Successful in 16m21s
Add places / things-to-do list with admin management
Backend: new Place GORM model (title, location, notes, image, category,
cost, priority, done) with auto-migration, a place.graphql schema, and
resolvers for the places query plus admin-only create/update/delete.
Regenerate gqlgen output against gqlgen v0.17.95, which requires Go 1.26 —
bump go.mod and the builder image to match.

Frontend: a places Pinia store, a CreatePlace admin form, and a
PlacesTable rendered as a new tab in the Collage cell, with inline
done-toggle and delete for admins. Rework the Admin page into a
sidebar-navigated panel layout (picking up the previously unreachable
CreateBookmark form) and give Login proper field labels, submit state,
and error feedback.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KcFtkisHcKJuTZAnv3fVzA
2026-09-12 18:10:41 +01:00

67 lines
1.1 KiB
Go

package services
import (
"fmt"
"adam-french.co.uk/backend/models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type SQLConfig struct {
User string
Password string
DBName string
Host string
Port string
}
func connectToPostgreSQL(config *SQLConfig) (*gorm.DB, error) {
dsn := fmt.Sprintf(
"user=%s password=%s dbname=%s host=%s port=%s sslmode=disable",
config.User, config.Password, config.DBName, config.Host, config.Port,
)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
return nil, err
}
return db, nil
}
func migrateDatabase(db *gorm.DB) error {
err := db.AutoMigrate(
&models.User{},
&models.Post{},
&models.Activity{},
&models.Favorite{},
&models.Rowing{},
&models.Message{},
&models.JobApplication{},
&models.JobAppReference{},
&models.Bookmark{},
&models.Place{},
&models.ProcessedEmail{},
)
if err != nil {
return err
}
return nil
}
func InitDatabase(config *SQLConfig) (*gorm.DB, error) {
db, err := connectToPostgreSQL(config)
if err != nil {
return nil, err
}
err = migrateDatabase(db)
if err != nil {
return nil, err
}
return db, nil
}