feat(db): update drizzle version

This commit is contained in:
Lars Hampe 2024-11-04 20:53:22 +01:00
parent abf009a045
commit a8392312c1
7 changed files with 54 additions and 46 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -12,14 +12,14 @@
"devDependencies": {
"@types/bun": "latest",
"@types/pg": "^8.11.10",
"drizzle-kit": "^0.24.2"
"drizzle-kit": "^0.27.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@boring.tools/logger": "workspace:*",
"drizzle-orm": "^0.33.0",
"drizzle-orm": "^0.36.0",
"pg": "^8.13.0"
}
}

View File

@ -0,0 +1,7 @@
import { timestamp, uuid } from 'drizzle-orm/pg-core'
export const _basic_schema = {
id: uuid().primaryKey(),
createdAt: timestamp({ withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp({ withTimezone: true }),
}

View File

@ -1,16 +1,17 @@
import { relations } from 'drizzle-orm'
import { pgTable, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core'
import { user } from '.'
import { _basic_schema } from './_basic'
export const access_token = pgTable('access_token', {
id: uuid('id').primaryKey().defaultRandom(),
userId: varchar('userId', { length: 32 }).references(() => user.id, {
..._basic_schema,
userId: varchar({ length: 32 }).references(() => user.id, {
onDelete: 'cascade',
}),
token: text('token').notNull(),
name: text('name').notNull(),
createdAt: timestamp('createdAt').defaultNow().notNull(),
lastUsedOn: timestamp('lastUsedOn'),
token: text().notNull(),
name: text().notNull(),
lastUsedOn: timestamp(),
})
export const access_token_relation = relations(access_token, ({ one }) => ({

View File

@ -11,33 +11,32 @@ import {
} from 'drizzle-orm/pg-core'
import { json } from 'drizzle-orm/pg-core'
import { uniqueIndex } from 'drizzle-orm/pg-core'
import { _basic_schema } from './_basic'
import { page } from './page'
import { user } from './user'
export const changelog = pgTable('changelog', {
id: uuid('id').primaryKey().defaultRandom(),
createdAt: timestamp('createdAt').defaultNow(),
updatedAt: timestamp('updatedAt'),
..._basic_schema,
userId: varchar('userId', { length: 32 }).references(() => user.id, {
userId: varchar({ length: 32 }).references(() => user.id, {
onDelete: 'cascade',
}),
pageId: uuid('pageId').references(() => page.id),
pageId: uuid().references(() => page.id),
title: varchar('title', { length: 256 }),
description: text('description'),
isSemver: boolean('isSemver').default(true),
isConventional: boolean('isConventional').default(true),
title: varchar({ length: 256 }),
description: text(),
isSemver: boolean().default(true),
isConventional: boolean().default(true),
})
export const changelogs_to_pages = pgTable(
'changelogs_to_pages',
{
changelogId: uuid('changelogId')
changelogId: uuid()
.notNull()
.references(() => changelog.id, { onDelete: 'cascade' }),
pageId: uuid('pageId')
pageId: uuid()
.notNull()
.references(() => page.id, { onDelete: 'cascade' }),
},
@ -77,50 +76,50 @@ export const changelog_version_status = pgEnum('status', [
])
export const changelog_version = pgTable('changelog_version', {
id: uuid('id').primaryKey().defaultRandom(),
createdAt: timestamp('createdAt').defaultNow(),
updatedAt: timestamp('updatedAt'),
releasedAt: timestamp('releasedAt'),
id: uuid().primaryKey().defaultRandom(),
createdAt: timestamp().defaultNow(),
updatedAt: timestamp(),
releasedAt: timestamp(),
changelogId: uuid('changelogId')
changelogId: uuid()
.references(() => changelog.id, {
onDelete: 'cascade',
})
.notNull(),
version: varchar('version', { length: 32 }).notNull(),
markdown: text('markdown').notNull(),
status: changelog_version_status('status').default('draft').notNull(),
version: varchar({ length: 32 }).notNull(),
markdown: text().notNull(),
status: changelog_version_status().default('draft').notNull(),
})
export const changelog_commit = pgTable(
'changelog_commit',
{
id: uuid('id').primaryKey().defaultRandom(),
createdAt: timestamp('createdAt'),
id: uuid().primaryKey().defaultRandom(),
createdAt: timestamp(),
changelogId: uuid('changelogId').references(() => changelog.id, {
changelogId: uuid().references(() => changelog.id, {
onDelete: 'cascade',
}),
versionId: uuid('versionId').references(() => changelog_version.id, {
versionId: uuid().references(() => changelog_version.id, {
onUpdate: 'set null',
}),
commit: varchar('commit', { length: 8 }).notNull(),
parent: varchar('parent', { length: 8 }),
subject: text('subject').notNull(),
author: json('author').$type<{
commit: varchar({ length: 8 }).notNull(),
parent: varchar({ length: 8 }),
subject: text().notNull(),
author: json().$type<{
name: string
email: string
date: string
}>(),
commiter: json('comitter').$type<{
commiter: json().$type<{
name: string
email: string
date: string
}>(),
body: text('body'),
body: text(),
},
(table) => ({
unique: uniqueIndex('unique').on(table.changelogId, table.commit),

View File

@ -1,18 +1,19 @@
import { relations } from 'drizzle-orm'
import { pgTable, text, uuid, varchar } from 'drizzle-orm/pg-core'
import { changelog, changelogs_to_pages } from './changelog'
import { _basic_schema } from './_basic'
import { changelogs_to_pages } from './changelog'
import { user } from './user'
export const page = pgTable('page', {
id: uuid('id').primaryKey().defaultRandom(),
..._basic_schema,
userId: varchar('userId', { length: 32 }).references(() => user.id, {
userId: varchar({ length: 32 }).references(() => user.id, {
onDelete: 'cascade',
}),
title: text('title').notNull(),
description: text('description').notNull(),
icon: text('icon').default(''),
title: text().notNull(),
description: text().notNull(),
icon: text().default(''),
})
export const pageRelation = relations(page, ({ many }) => ({

View File

@ -4,9 +4,9 @@ import { access_token } from '.'
import { changelog } from './changelog'
export const user = pgTable('user', {
id: varchar('id', { length: 32 }).primaryKey(), // Clerk User Id
name: text('name'),
email: text('email').notNull().unique(),
id: varchar({ length: 32 }).primaryKey(), // Clerk User Id
name: text(),
email: text().notNull().unique(),
})
export const userRelation = relations(user, ({ many }) => ({