Skip to content

Commit

Permalink
Remove isInLocalDb flag, start dumping saves into S3
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Oct 30, 2024
1 parent ad8fa03 commit 07c60d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
6 changes: 3 additions & 3 deletions api/daily/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 IF EXISTS isInLocalDb`,
}

for _, q := range queries {
Expand Down
20 changes: 3 additions & 17 deletions db/savedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

0 comments on commit 07c60d8

Please sign in to comment.