Migrate from postgres to sqlite

This commit is contained in:
2024-09-03 19:51:37 +02:00
parent 67aa65386e
commit 8b97e64b59
13 changed files with 474 additions and 461 deletions

View File

@@ -1,5 +1,4 @@
import postgres from 'postgres'
import { drizzle } from 'drizzle-orm/postgres-js'
import { drizzle } from 'drizzle-orm/d1'
import * as schema from '../database/schema'
export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
@@ -7,8 +6,7 @@ export { sql, eq, and, or, asc, desc, sum, isNull } from 'drizzle-orm'
export const tables = schema
export function useDrizzle() {
const config = useRuntimeConfig()
return drizzle(postgres(config.postgres.url, { prepare: false, max: 50 }), { schema })
return drizzle(hubDatabase(), { schema })
}
export type UserInsert = typeof schema.users.$inferInsert

View File

@@ -1,11 +1,15 @@
import { serial, timestamp } from 'drizzle-orm/pg-core'
/**
* A centralized list of standardized Drizzle ORM schema field definitions to prevent duplication errors
*/
import { integer } from 'drizzle-orm/sqlite-core'
export const createdAt = timestamp('created_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow()
export const updatedAt = timestamp('updated_at', { mode: 'string', withTimezone: true, precision: 0 }).defaultNow().$onUpdateFn(() => sql`(current_timestamp)`)
export const id = serial('id').primaryKey()
export const id = integer('id').primaryKey()
export const createdAt
= integer('created_at', { mode: 'timestamp' })
.$defaultFn(() => new Date())
export const updatedAt
= integer('updated_at', { mode: 'timestamp' })
.$onUpdateFn(() => new Date())
.$defaultFn(() => new Date())
export const timestamps = {
createdAt,