mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
119 lines
3.1 KiB
Go
119 lines
3.1 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type UpgradeCheck struct {
|
|
HasNamedVolumes bool
|
|
NeedsPostgresMigration bool
|
|
NeedsStorageMigration bool
|
|
PostgresBackupFile string
|
|
StorageMigrationStatus string
|
|
}
|
|
|
|
func CheckUpgradeRequirements() (*UpgradeCheck, error) {
|
|
check := &UpgradeCheck{}
|
|
|
|
postgres, datastore := CheckDockerVolumes()
|
|
check.HasNamedVolumes = postgres && datastore
|
|
|
|
check.NeedsPostgresMigration = checkPostgres12InCompose()
|
|
|
|
check.StorageMigrationStatus = ReadEnvValue("SESSION_RECORDING_STORAGE_MIGRATED_TO_SEAWEEDFS")
|
|
check.NeedsStorageMigration = check.StorageMigrationStatus == ""
|
|
|
|
return check, nil
|
|
}
|
|
|
|
func GetVolumeWarning() string {
|
|
postgres, datastore := CheckDockerVolumes()
|
|
if postgres && datastore {
|
|
return ""
|
|
}
|
|
|
|
return `WARNING: POTENTIAL DATA LOSS
|
|
|
|
We were unable to find named datastore and postgres volumes.
|
|
If you created your Insights stack PRIOR TO August 12th, 2022 / v1.39.0,
|
|
the Postgres and Datastore containers did NOT have persistent named volumes by default.
|
|
|
|
If you choose to upgrade, you will likely lose data contained in these anonymous volumes.
|
|
|
|
See: https://github.com/Insights/insights/pull/11256
|
|
|
|
WE STRONGLY RECOMMEND YOU:
|
|
• Stop and back up your entire environment
|
|
• Back up /var/lib/postgresql/data in the postgres container
|
|
• Back up /var/lib/datastore in the datastore container`
|
|
}
|
|
|
|
func checkPostgres12InCompose() bool {
|
|
data, err := os.ReadFile("insights/docker-compose.hobby.yml")
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
content := string(data)
|
|
return strings.Contains(content, "postgres:12-alpine") || strings.Contains(content, "postgres:12")
|
|
}
|
|
|
|
func BackupPostgres12() (string, error) {
|
|
backupFile := fmt.Sprintf("backup_pg12_%s.sql.gz", time.Now().Format("20060102_150405"))
|
|
|
|
if err := BackupPostgres(backupFile); err != nil {
|
|
return "", fmt.Errorf("backup failed: %w", err)
|
|
}
|
|
|
|
if !FileExists(backupFile) {
|
|
return "", fmt.Errorf("backup file was not created")
|
|
}
|
|
|
|
info, err := os.Stat(backupFile)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if info.Size() < 1000 {
|
|
_ = os.Remove(backupFile)
|
|
return "", fmt.Errorf("backup file too small (%d bytes)", info.Size())
|
|
}
|
|
|
|
return backupFile, nil
|
|
}
|
|
|
|
func MigratePostgres12To15(backupFile string) error {
|
|
if err := DockerComposeDown(); err != nil {
|
|
return fmt.Errorf("failed to stop stack: %w", err)
|
|
}
|
|
|
|
// Ignore error, volume might not exist
|
|
_ = DockerVolumeRemove("postgres-data")
|
|
|
|
return nil
|
|
}
|
|
|
|
func RestorePostgres15(backupFile string) error {
|
|
if err := DockerComposeUpDB(); err != nil {
|
|
return fmt.Errorf("failed to start database: %w", err)
|
|
}
|
|
|
|
time.Sleep(20 * time.Second)
|
|
|
|
if err := RestorePostgres(backupFile); err != nil {
|
|
return fmt.Errorf("failed to restore backup: %w", err)
|
|
}
|
|
|
|
cmd, args := GetDockerComposeCommand()
|
|
fullArgs := append(args, "exec", "-T", "db", "psql", "-U", "insights", "-c", "ALTER USER insights WITH PASSWORD 'insights';")
|
|
_, _ = RunCommand(cmd, fullArgs...) // Best-effort password reset
|
|
|
|
return nil
|
|
}
|
|
|
|
func SetStorageMigrationStatus(status string) error {
|
|
return AppendToEnv("SESSION_RECORDING_STORAGE_MIGRATED_TO_SEAWEEDFS", status)
|
|
}
|