Skip to content

Commit

Permalink
fix: stop the API from trying to update the levels column since it's …
Browse files Browse the repository at this point in the history
…an auto-generated one.

- stats tables will be backed up before this goes live in case anything goes wrong.
- if anything does go wrong, stats will be rolled back to this backup
  • Loading branch information
Torwent committed Feb 15, 2024
1 parent 0a70e6a commit c486c6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/lib/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ async function updateScriptData(script_id: string, payload: Stats) {
experience: entry.experience,
gold: entry.gold,
runtime: entry.runtime,
levels: undefined,
unique_users: entry.unique_users,
online_users: entry.online_users.map((user) => user as unknown as Json)
})
Expand Down Expand Up @@ -247,7 +246,6 @@ export async function upsertPlayerData(id: string, rawPayload: RawPayload) {
experience: payload.experience,
gold: payload.gold,
runtime: payload.runtime,
levels: 0,
password: "",
updated_at: null
}
Expand All @@ -273,8 +271,7 @@ export async function upsertPlayerData(id: string, rawPayload: RawPayload) {
.update({
experience: (entry.experience ?? 0) + oldData.experience,
gold: (entry.gold ?? 0) + oldData.gold,
runtime: (entry.runtime ?? 0) + oldData.runtime,
levels: undefined
runtime: (entry.runtime ?? 0) + oldData.runtime
})
.eq("id", id)

Expand All @@ -294,7 +291,6 @@ export async function upsertPlayerData(id: string, rawPayload: RawPayload) {
experience: payload.experience,
gold: payload.gold,
runtime: payload.runtime,
levels: 0,
password: "",
updated_at: null,
username: ""
Expand Down
10 changes: 9 additions & 1 deletion src/lib/types/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export interface Profile extends ProfileBase {
subscriptions: ProfileSubscription
}

export type Stats = Database["public"]["Tables"]["stats"]["Row"]
export type Stats = {
experience: number
gold: number
id: string
password: string
runtime: number
updated_at: string
username: string
}

export type ScriptBase = Database["scripts"]["Tables"]["scripts"]["Row"]
export type ScriptProtected = Database["scripts"]["Tables"]["protected"]["Row"]
Expand Down

0 comments on commit c486c6b

Please sign in to comment.