diff --git a/app/db/models/badges.server.ts b/app/db/models/badges.server.ts index f5c18e757..03f2d6def 100644 --- a/app/db/models/badges.server.ts +++ b/app/db/models/badges.server.ts @@ -2,11 +2,11 @@ import { sql } from "../sql"; import type { Badge, User } from "../types"; const countsByUserIdStm = sql.prepare(` - select "Badge"."code", "Badge"."displayName", count("BadgeOwner"."code") as count + select "Badge"."code", "Badge"."displayName", count("BadgeOwner"."badgeId") as count from "BadgeOwner" - join "Badge" on "Badge"."code" = "BadgeOwner"."code" + join "Badge" on "Badge"."id" = "BadgeOwner"."badgeId" where "BadgeOwner"."userId" = $userId - group by "BadgeOwner"."code", "BadgeOwner"."userId" + group by "BadgeOwner"."badgeId", "BadgeOwner"."userId" `); export type CountsByUserId = Array< diff --git a/app/db/seed.ts b/app/db/seed.ts index 1ccf5dadf..fa4e0fcc8 100644 --- a/app/db/seed.ts +++ b/app/db/seed.ts @@ -202,22 +202,22 @@ function thisMonthsSuggestions() { function badgesToAdmin() { const availableBadgeCodes = shuffle( sql - .prepare(`select "code" from "Badge"`) + .prepare(`select "id" from "Badge"`) .all() - .map((b) => b.code) - ).slice(0, 8) as string[]; + .map((b) => b.id) + ).slice(0, 8) as number[]; - const badgesWithDuplicates = availableBadgeCodes.flatMap((code) => + const badgesWithDuplicates = availableBadgeCodes.flatMap((id) => new Array(faker.helpers.arrayElement([1, 1, 1, 2, 3, 4])) .fill(null) - .map(() => code) + .map(() => id) ); - for (const code of badgesWithDuplicates) { + for (const id of badgesWithDuplicates) { sql .prepare( - `insert into "BadgeOwner" ("code", "userId") values ($code, $userId)` + `insert into "BadgeOwner" ("badgeId", "userId") values ($id, $userId)` ) - .run({ code, userId: 1 }); + .run({ id, userId: 1 }); } } diff --git a/app/db/types.ts b/app/db/types.ts index 5e8d92282..ff3740b90 100644 --- a/app/db/types.ts +++ b/app/db/types.ts @@ -53,16 +53,17 @@ export interface PlusTier { } export interface Badge { + id: number; code: string; displayName: string; } export interface BadgeOwner { - code: string; + badgeId: number; userId: number; } export interface BadgeManager { - code: string; + badgeId: number; userId: number; } diff --git a/migrations/001-badges.js b/migrations/001-badges.js index d9f663630..893b35c4d 100644 --- a/migrations/001-badges.js +++ b/migrations/001-badges.js @@ -2,7 +2,8 @@ module.exports.up = function (db) { db.prepare( ` create table "Badge" ( - "code" text not null primary key, + "id" integer primary key, + "code" text not null, "displayName" text not null ) strict ` @@ -17,7 +18,7 @@ module.exports.up = function (db) { db.prepare( ` create table "BadgeOwner" ( - "code" text not null, + "badgeId" integer not null, "userId" integer not null ) strict ` @@ -26,9 +27,9 @@ module.exports.up = function (db) { db.prepare( ` create table "BadgeManager" ( - "code" text not null, + "badgeId" integer not null, "userId" integer not null, - unique("code", "userId") on conflict rollback + unique("badgeId", "userId") on conflict rollback ) strict ` ).run(); @@ -163,7 +164,7 @@ function initialBadgesForDb() { displayName: "LUTI Season 12 (Div 8)", }, { - code: "lutitan2", + code: "lutitan", displayName: "LUTI Season 12 (Div 9)", }, { diff --git a/public/gif/badges/lutitan2.gif b/public/gif/badges/lutitan2.gif deleted file mode 100644 index 34d242588..000000000 Binary files a/public/gif/badges/lutitan2.gif and /dev/null differ