pull/715/head
Travis Fischer 2025-05-20 17:05:52 +07:00
rodzic 6b36a91aa7
commit fbbbc0f2f2
1 zmienionych plików z 17 dodań i 17 usunięć

Wyświetl plik

@ -33,13 +33,29 @@ export const idPrefixMap = {
export type ModelType = keyof typeof idPrefixMap
export function createId(modelType: ModelType): string {
function createIdForModel(modelType: ModelType): string {
const prefix = idPrefixMap[modelType]
assert(prefix, 500, `Invalid model type: ${modelType}`)
return `${prefix}_${createCuid2()}`
}
/**
* Returns the `id` primary key to use for a given model type.
*/
function getPrimaryId(modelType: ModelType) {
return id()
.primaryKey()
.$defaultFn(() => createIdForModel(modelType))
}
export const projectPrimaryId = getPrimaryId('project')
export const deploymentPrimaryId = getPrimaryId('deployment')
export const consumerPrimaryId = getPrimaryId('consumer')
export const logEntryPrimaryId = getPrimaryId('logEntry')
export const teamPrimaryId = getPrimaryId('team')
export const userPrimaryId = getPrimaryId('user')
/**
* All of our model primary ids have the following format:
*
@ -51,22 +67,6 @@ export function id<U extends string, T extends Readonly<[U, ...U[]]>>(
return varchar({ length: idMaxLength, ...config })
}
/**
* Returns the `id` primary key to use for a given model type.
*/
function getPrimaryId(modelType: ModelType) {
return id()
.primaryKey()
.$defaultFn(() => createId(modelType))
}
export const projectPrimaryId = getPrimaryId('project')
export const deploymentPrimaryId = getPrimaryId('deployment')
export const consumerPrimaryId = getPrimaryId('consumer')
export const logEntryPrimaryId = getPrimaryId('logEntry')
export const teamPrimaryId = getPrimaryId('team')
export const userPrimaryId = getPrimaryId('user')
export const projectId = id
export const deploymentId = id
export const consumerId = id