Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions shared/database/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,19 @@ export const shows = wxyc_schema.table('shows', {

export type NewShowDJ = InferInsertModel<typeof show_djs>;
export type ShowDJ = InferSelectModel<typeof show_djs>;
export const show_djs = wxyc_schema.table('show_djs', {
show_id: integer('show_id')
.references(() => shows.id)
.notNull(),
dj_id: varchar('dj_id', { length: 255 })
.references(() => user.id, { onDelete: 'cascade' })
.notNull(),
active: boolean('active').default(true),
});
export const show_djs = wxyc_schema.table(
'show_djs',
{
show_id: integer('show_id')
.references(() => shows.id)
.notNull(),
dj_id: varchar('dj_id', { length: 255 })
.references(() => user.id, { onDelete: 'cascade' })
.notNull(),
active: boolean('active').default(true),
},
(table) => [uniqueIndex('show_djs_show_id_dj_id_unique').on(table.show_id, table.dj_id)]
);

//create entry w/ ID 0 for regular shows
export type NewSpecialtyShow = InferInsertModel<typeof specialty_shows>;
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/database/schema.show-djs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getTableConfig } from 'drizzle-orm/pg-core';
import { show_djs } from '../../../shared/database/src/schema';

describe('show_djs schema', () => {
it('has a unique index on (show_id, dj_id)', () => {
const config = getTableConfig(show_djs);
const uniqueIndexes = config.indexes.filter((idx) => idx.config.unique);

const showDjIndex = uniqueIndexes.find(
(idx) =>
idx.config.columns.length === 2 &&
idx.config.columns.some((col) => 'name' in col && col.name === 'show_id') &&
idx.config.columns.some((col) => 'name' in col && col.name === 'dj_id')
);

expect(showDjIndex).toBeDefined();
});
});
Loading