How to reference composite key in foreign key

I'm trying to create a foreign key which points to another tables composite primary key. I cannot seem to find anywhere how this is meant to be achieved.

I have attached a simplified version of the code I am trying to get to work. As you can see in the moves table I am creating a composite primary key. How do I then reference that in the moveTimestamps table. Also, what should I put in place of varchar in the moveTimestamps table move column, typically I would just match the data type as what it is referencing, but in thise case it should reference both an interger and a varchar.

const moves = pgTable(
  "moves",
  {
    gameID: varchar("game_id")
      .notNull()
      .references(() => games.id, { onDelete: "cascade" }),
    turn: integer("turn").notNull().unique(),  },
  (table) => {
    return {
      pk: primaryKey({ name: "id", columns: [table.gameID, table.turn] }),
    };
  },
);


export const moveTimestamps = pgTable("moveTimestamps", {
  move: varchar("move")
    .notNull()
    .references(() => //!What do i put here!)
    .primaryKey(),
});
Was this page helpful?