From 5480c2ee720865fac4b945c3e5fd73ff81db5935 Mon Sep 17 00:00:00 2001 From: Pancakes Date: Tue, 29 Oct 2024 21:26:10 -0400 Subject: [PATCH] Remove isInLocalDb flag, start dumping saves into S3 --- api/daily/common.go | 6 +++--- db/db.go | 5 +++++ db/savedata.go | 20 +++----------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/api/daily/common.go b/api/daily/common.go index a3bc753..84b8167 100644 --- a/api/daily/common.go +++ b/api/daily/common.go @@ -132,7 +132,7 @@ func S3SaveMigration() error { } // retrieve accounts from db - accounts, err := db.GetLocalAccounts() + accounts, err := db.GetLocalSystemAccounts() if err != nil { return fmt.Errorf("failed to retrieve old accounts: %s", err) } @@ -163,9 +163,9 @@ func S3SaveMigration() error { continue } - err = db.UpdateSystemSaveLocation(user) + err = db.DeleteSystemSaveData(user) if err != nil { - log.Printf("failed to update location for user %s: %s", username, err) + log.Printf("failed to delete old save for user %s: %s", username, err) continue } diff --git a/db/db.go b/db/db.go index 04fec2d..d086abb 100644 --- a/db/db.go +++ b/db/db.go @@ -108,6 +108,11 @@ func setupDb(tx *sql.Tx) error { // MIGRATION 004 `ALTER TABLE accounts ADD COLUMN IF NOT EXISTS isInLocalDb TINYINT(1) NOT NULL DEFAULT 1`, + + // ---------------------------------- + // MIGRATION 005 + + `ALTER TABLE accounts DROP COLUMN IF EXISTS isInLocalDb`, } for _, q := range queries { diff --git a/db/savedata.go b/db/savedata.go index 6b5b4b0..8855c2e 100644 --- a/db/savedata.go +++ b/db/savedata.go @@ -98,7 +98,7 @@ func ReadSystemSaveData(uuid []byte) (defs.SystemSaveData, error) { } // delete the one in db - err = UpdateSystemSaveLocation(uuid) + err = DeleteSystemSaveData(uuid) if err != nil { return system, err } @@ -259,9 +259,9 @@ func GetSystemSaveFromS3(uuid []byte) (defs.SystemSaveData, error) { return session, nil } -func GetLocalAccounts() ([][]byte, error) { +func GetLocalSystemAccounts() ([][]byte, error) { var users [][]byte - rows, err := handle.Query("SELECT uuid FROM accounts WHERE isInLocalDb = 1) LIMIT 3000") + rows, err := handle.Query("SELECT uuid FROM systemSaveData LIMIT 3000") if err != nil { return nil, err } @@ -280,17 +280,3 @@ func GetLocalAccounts() ([][]byte, error) { return users, nil } - -func UpdateSystemSaveLocation(uuid []byte) error { - _, err := handle.Exec("UPDATE accounts SET isInLocalDb = 0 WHERE uuid = ?", uuid) - if err != nil { - return err - } - - err = DeleteSystemSaveData(uuid) - if err != nil { - return err - } - - return nil -}