Skip to content

Commit

Permalink
Add item metadata table
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Mar 4, 2024
1 parent eceed16 commit 09e7fe8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1110,3 +1110,11 @@ model GiftBox {
@@map("gift_box")
}

model ItemMetadata {
id Int @id
name String?
@@map("item_metadata")
}
14 changes: 14 additions & 0 deletions src/lib/startupScripts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Items } from 'oldschooljs';

import { prisma } from './settings/prisma';
import { logError } from './util/logError';

Expand Down Expand Up @@ -121,6 +123,18 @@ startupScripts.push({
sql: 'CREATE UNIQUE INDEX IF NOT EXISTS activity_only_one_task ON activity (user_id, completed) WHERE NOT completed;'
});

const itemMetaDataNames = Items.map(item => `(${item.id}, '${item.name.replace(/'/g, "''")}')`).join(', ');
const itemMetaDataQuery = `
INSERT INTO item_metadata (id, name)
VALUES ${itemMetaDataNames}
ON CONFLICT (id)
DO
UPDATE SET name = EXCLUDED.name
WHERE item_metadata.name IS DISTINCT FROM EXCLUDED.name;
`;

startupScripts.push({ sql: itemMetaDataQuery });

export async function runStartupScripts() {
for (const query of startupScripts) {
await prisma
Expand Down

0 comments on commit 09e7fe8

Please sign in to comment.