schema patched
This commit is contained in:
parent
36b937c5b6
commit
62127cc5e4
5 changed files with 29 additions and 24 deletions
|
@ -1,6 +1,8 @@
|
|||
import * as t from 'drizzle-orm/pg-core';
|
||||
import { timestamps } from '../util';
|
||||
import { competitions } from './competitions';
|
||||
import { rounds } from './rounds';
|
||||
import { relations } from 'drizzle-orm';
|
||||
|
||||
export const bracketTypes = t.pgEnum('bracket_type', ['WINNER', 'LOSER', 'CONSOLATION', 'MAIN']);
|
||||
|
||||
|
@ -10,9 +12,14 @@ export const brackets = t.pgTable('brackets', {
|
|||
bracketType: bracketTypes('bracket_type').notNull(),
|
||||
position: t.integer('position').default(1).notNull(),
|
||||
isActive: t.boolean('is_active').default(true).notNull(),
|
||||
competition_id: t
|
||||
.uuid('competition_id')
|
||||
.notNull()
|
||||
.references(() => competitions.id, { onDelete: 'cascade' }),
|
||||
competition_id: t.uuid('competition_id').notNull(),
|
||||
...timestamps
|
||||
});
|
||||
|
||||
export const bracketsRelations = relations(brackets, ({ many, one }) => ({
|
||||
competition: one(competitions, {
|
||||
fields: [brackets.competition_id],
|
||||
references: [competitions.id]
|
||||
}),
|
||||
rounds: many(rounds)
|
||||
}));
|
||||
|
|
|
@ -8,29 +8,27 @@ import { brackets } from './brackets';
|
|||
|
||||
export const schedulingModes = t.pgEnum('scheduling_modes', enumToPgEnum(SchedulingMode));
|
||||
|
||||
export const rounds = t.pgTable(
|
||||
'rounds',
|
||||
{
|
||||
id: t.uuid('id').primaryKey().defaultRandom(),
|
||||
name: t.text('name').notNull(),
|
||||
round_number: t.integer('round_number').notNull(),
|
||||
nb_matches: t.integer('nb_matches').notNull(),
|
||||
competition_id: t.uuid('competition_id').notNull(),
|
||||
scheduling_mode: schedulingModes('scheduling_modes'),
|
||||
bracket_id: t.uuid('bracket_id').references(() => brackets.id),
|
||||
...timestamps
|
||||
},
|
||||
(table) => ({
|
||||
uniqueCompetitionRound: t.unique().on(table.competition_id, table.round_number)
|
||||
})
|
||||
);
|
||||
export const rounds = t.pgTable('rounds', {
|
||||
id: t.uuid('id').primaryKey().defaultRandom(),
|
||||
name: t.text('name').notNull(),
|
||||
round_number: t.integer('round_number').notNull(),
|
||||
nb_matches: t.integer('nb_matches').notNull(),
|
||||
competition_id: t.uuid('competition_id').notNull(),
|
||||
scheduling_mode: schedulingModes('scheduling_modes'),
|
||||
bracket_id: t.uuid('bracket_id'),
|
||||
...timestamps
|
||||
});
|
||||
|
||||
export const roundsRelations = relations(rounds, ({ many, one }) => ({
|
||||
competition: one(competitions, {
|
||||
fields: [rounds.competition_id],
|
||||
references: [competitions.id]
|
||||
}),
|
||||
matches: many(matches)
|
||||
matches: many(matches),
|
||||
bracket: one(brackets, {
|
||||
fields: [rounds.bracket_id],
|
||||
references: [brackets.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export type Round = typeof rounds.$inferSelect;
|
||||
|
|
|
@ -69,7 +69,7 @@ export const usersToPermissions = t.pgTable(
|
|||
.notNull()
|
||||
.references(() => users.id),
|
||||
permission_id: t
|
||||
.integer('permission_id')
|
||||
.uuid('permission_id')
|
||||
.notNull()
|
||||
.references(() => permissions.id),
|
||||
granted: t.boolean('granted').notNull(),
|
||||
|
|
|
@ -3,7 +3,7 @@ import { users } from './users';
|
|||
import { binaryHash, timestamps } from '../util';
|
||||
|
||||
export const sessions = t.pgTable('session', {
|
||||
id: t.text('id').primaryKey(),
|
||||
id: t.uuid('id').primaryKey(),
|
||||
secret_hash: binaryHash('secret_hash').notNull(),
|
||||
user_id: t
|
||||
.uuid('user_id')
|
||||
|
|
|
@ -4,7 +4,7 @@ import { relations } from 'drizzle-orm';
|
|||
import { timestamps } from '../util';
|
||||
|
||||
export const users = t.pgTable('user', {
|
||||
id: t.text('id').primaryKey(),
|
||||
id: t.uuid('id').primaryKey(),
|
||||
username: t.text('username').notNull().unique(),
|
||||
oauth_id: t.uuid('oauth_id').notNull(),
|
||||
email: t.text('email').notNull().unique(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue