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 * as t from 'drizzle-orm/pg-core';
|
||||||
import { timestamps } from '../util';
|
import { timestamps } from '../util';
|
||||||
import { competitions } from './competitions';
|
import { competitions } from './competitions';
|
||||||
|
import { rounds } from './rounds';
|
||||||
|
import { relations } from 'drizzle-orm';
|
||||||
|
|
||||||
export const bracketTypes = t.pgEnum('bracket_type', ['WINNER', 'LOSER', 'CONSOLATION', 'MAIN']);
|
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(),
|
bracketType: bracketTypes('bracket_type').notNull(),
|
||||||
position: t.integer('position').default(1).notNull(),
|
position: t.integer('position').default(1).notNull(),
|
||||||
isActive: t.boolean('is_active').default(true).notNull(),
|
isActive: t.boolean('is_active').default(true).notNull(),
|
||||||
competition_id: t
|
competition_id: t.uuid('competition_id').notNull(),
|
||||||
.uuid('competition_id')
|
|
||||||
.notNull()
|
|
||||||
.references(() => competitions.id, { onDelete: 'cascade' }),
|
|
||||||
...timestamps
|
...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 schedulingModes = t.pgEnum('scheduling_modes', enumToPgEnum(SchedulingMode));
|
||||||
|
|
||||||
export const rounds = t.pgTable(
|
export const rounds = t.pgTable('rounds', {
|
||||||
'rounds',
|
|
||||||
{
|
|
||||||
id: t.uuid('id').primaryKey().defaultRandom(),
|
id: t.uuid('id').primaryKey().defaultRandom(),
|
||||||
name: t.text('name').notNull(),
|
name: t.text('name').notNull(),
|
||||||
round_number: t.integer('round_number').notNull(),
|
round_number: t.integer('round_number').notNull(),
|
||||||
nb_matches: t.integer('nb_matches').notNull(),
|
nb_matches: t.integer('nb_matches').notNull(),
|
||||||
competition_id: t.uuid('competition_id').notNull(),
|
competition_id: t.uuid('competition_id').notNull(),
|
||||||
scheduling_mode: schedulingModes('scheduling_modes'),
|
scheduling_mode: schedulingModes('scheduling_modes'),
|
||||||
bracket_id: t.uuid('bracket_id').references(() => brackets.id),
|
bracket_id: t.uuid('bracket_id'),
|
||||||
...timestamps
|
...timestamps
|
||||||
},
|
});
|
||||||
(table) => ({
|
|
||||||
uniqueCompetitionRound: t.unique().on(table.competition_id, table.round_number)
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const roundsRelations = relations(rounds, ({ many, one }) => ({
|
export const roundsRelations = relations(rounds, ({ many, one }) => ({
|
||||||
competition: one(competitions, {
|
competition: one(competitions, {
|
||||||
fields: [rounds.competition_id],
|
fields: [rounds.competition_id],
|
||||||
references: [competitions.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;
|
export type Round = typeof rounds.$inferSelect;
|
||||||
|
|
|
@ -69,7 +69,7 @@ export const usersToPermissions = t.pgTable(
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id),
|
.references(() => users.id),
|
||||||
permission_id: t
|
permission_id: t
|
||||||
.integer('permission_id')
|
.uuid('permission_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => permissions.id),
|
.references(() => permissions.id),
|
||||||
granted: t.boolean('granted').notNull(),
|
granted: t.boolean('granted').notNull(),
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { users } from './users';
|
||||||
import { binaryHash, timestamps } from '../util';
|
import { binaryHash, timestamps } from '../util';
|
||||||
|
|
||||||
export const sessions = t.pgTable('session', {
|
export const sessions = t.pgTable('session', {
|
||||||
id: t.text('id').primaryKey(),
|
id: t.uuid('id').primaryKey(),
|
||||||
secret_hash: binaryHash('secret_hash').notNull(),
|
secret_hash: binaryHash('secret_hash').notNull(),
|
||||||
user_id: t
|
user_id: t
|
||||||
.uuid('user_id')
|
.uuid('user_id')
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { relations } from 'drizzle-orm';
|
||||||
import { timestamps } from '../util';
|
import { timestamps } from '../util';
|
||||||
|
|
||||||
export const users = t.pgTable('user', {
|
export const users = t.pgTable('user', {
|
||||||
id: t.text('id').primaryKey(),
|
id: t.uuid('id').primaryKey(),
|
||||||
username: t.text('username').notNull().unique(),
|
username: t.text('username').notNull().unique(),
|
||||||
oauth_id: t.uuid('oauth_id').notNull(),
|
oauth_id: t.uuid('oauth_id').notNull(),
|
||||||
email: t.text('email').notNull().unique(),
|
email: t.text('email').notNull().unique(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue