Skip to content

Commit

Permalink
πŸ› primary key for vote table (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax authored Sep 15, 2023
1 parent 90d65c0 commit e77aa49
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/back-end/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserInfo } from "remult";
import { UserInfo, dbNamesOf } from "remult";
import { remultExpress } from "remult/remult-express";
import { createKnexDataProvider } from "remult/remult-knex";
import { KnexDataProvider, createKnexDataProvider } from "remult/remult-knex";
import { Story } from "../models/story";
import { Vote } from "../models/vote";

Expand All @@ -21,6 +21,17 @@ const server = remultExpress({

return await new Promise((resolve) => resolve(user));
},
async initApi() {
// add a unique index that will serve in place of a compound primary key
const db = KnexDataProvider.getDb();
const table = (await dbNamesOf(Vote)).$entityName;

await db.raw(`
create unique index if not exists
idx_vote_compound_key
on ${table} (participantId, storyId)
`);
},
});

export default server;

0 comments on commit e77aa49

Please sign in to comment.