Added userID in history table for per profile history, reworked primary key. Profile recent history table

This commit is contained in:
2026-02-05 03:16:05 -08:00
parent 0043d83330
commit 813f510a9e
9 changed files with 426 additions and 285 deletions

38
main.go
View File

@@ -1,18 +1,22 @@
package main
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"muzi/db"
"muzi/migrate"
"muzi/web"
"github.com/jackc/pgx/v5"
)
func dbCheck() error {
if !migrate.DbExists() {
err := migrate.CreateDB()
if !db.DbExists() {
err := db.CreateDB()
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating muzi DB: %v\n", err)
return err
@@ -68,14 +72,40 @@ func main() {
return
}
fmt.Println("Setting up database tables...")
conn, err := pgx.Connect(
context.Background(),
"postgres://postgres:postgres@localhost:5432/muzi",
)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot connect to muzi database: %v\n", err)
return
}
defer conn.Close(context.Background())
err = db.CreateHistoryTable(conn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating history table: %v\n", err)
return
}
err = db.CreateUsersTable(conn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating users table: %v\n", err)
return
}
username := ""
apiKey := ""
fmt.Printf("Importing LastFM data for %s\n", username)
err = migrate.ImportLastFM(username, apiKey)
// TODO:
// remove hardcoded userID by creating webUI import pages and getting
// userID from login session
err = migrate.ImportLastFM(username, apiKey, 1)
if err != nil {
return
}
err = migrate.ImportSpotify()
err = migrate.ImportSpotify(1)
if err != nil {
return
}