Skip to content

Commit

Permalink
add more index
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Nov 26, 2024
1 parent 23968e1 commit 48a1abc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/shelve/server/database/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boolean, integer, pgEnum, pgTable, varchar, uniqueIndex } from 'drizzle-orm/pg-core'
import { boolean, integer, pgEnum, pgTable, varchar, index, uniqueIndex } from 'drizzle-orm/pg-core'
import { AuthType, Role, TeamRole } from '@shelve/types'
import { relations } from 'drizzle-orm'
import { timestamps } from './column.helpers'
Expand Down Expand Up @@ -36,15 +36,19 @@ export const teams = pgTable('teams', {
private: boolean().default(true).notNull(),
privateOf: integer().references(() => users.id, { onDelete: 'cascade' }),
...timestamps,
})
}, (table) => [index('teams_private_of_idx').on(table.privateOf)])

export const members = pgTable('members', {
id: integer().primaryKey().generatedByDefaultAsIdentity(),
userId: integer().references(() => users.id, { onDelete: 'cascade' }).notNull(),
teamId: integer().references(() => teams.id, { onDelete: 'cascade' }).notNull(),
role: teamRoleEnum().default(TeamRole.MEMBER).notNull(),
...timestamps,
})
}, (table) => [
uniqueIndex('members_user_team_idx').on(table.userId, table.teamId),
index('members_role_idx').on(table.role),
index('members_team_role_idx').on(table.teamId, table.role)
])

export const projects = pgTable('projects', {
id: integer().primaryKey().generatedByDefaultAsIdentity(),
Expand All @@ -65,8 +69,8 @@ export const variables = pgTable('variables', {
key: varchar().notNull(),
...timestamps,
}, (table) => [
uniqueIndex('idx_variables_project_key').on(table.projectId, table.key),
uniqueIndex('idx_variables_project').on(table.projectId)
uniqueIndex('variables_project_key_idx').on(table.projectId, table.key),
index('variables_key_idx').on(table.key)
])

export const variableValues = pgTable('variable_values', {
Expand Down Expand Up @@ -95,7 +99,10 @@ export const environments = pgTable('environments', {
name: varchar().notNull(),
teamId: integer().references(() => teams.id, { onDelete: 'cascade' }).notNull(),
...timestamps,
})
}, (table) => [
uniqueIndex('environments_team_name_idx').on(table.teamId, table.name),
index('environments_team_idx').on(table.teamId),
])

export const teamsRelations = relations(teams, ({ many }) => ({
members: many(members),
Expand Down

0 comments on commit 48a1abc

Please sign in to comment.