Skip to content

Commit

Permalink
keep timestamps as-is for now
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWitchBella committed Apr 7, 2024
1 parent 321c8b7 commit c93b3dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 10 additions & 1 deletion workers/src/db/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ function mkDrizzle(): DB {
console.info('Using the local database')
let url = process.env.POSTGRESQL_URL
if (!url) throw new Error('Missing POSTGRESQL_URL env')
const connection = postgres(url)
const connection = postgres(url, {
types: {
date: {
to: 1184,
from: [1082, 1083, 1114, 1184],
serialize: (x: any) => x,
parse: (x: any) => x,
},
},
})

const db = pgDrizzle(connection, { schema })
return db
Expand Down
17 changes: 9 additions & 8 deletions workers/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'drizzle-orm/pg-core'

const id = serial('id').primaryKey()
const timestampCfg = { mode: 'string', withTimezone: true } as const

export const user = pgTable('user', {
id,
Expand All @@ -21,7 +22,7 @@ export const user = pgTable('user', {
email: varchar('email', { length: 256 }).notNull().unique(),
admin: boolean('admin').notNull().default(false),
passwordHash: varchar('password_hash', { length: 256 }).notNull(),
registeredAt: timestamp('registered_at', { mode: 'string' })
registeredAt: timestamp('registered_at', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
})
Expand All @@ -36,10 +37,10 @@ export const song = pgTable('song', {
text: text('text').notNull(),

fontSize: real('font_size').default(1).notNull(),
lastModified: timestamp('last_modified', { mode: 'string' })
lastModified: timestamp('last_modified', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
insertedAt: timestamp('inserted_at', { mode: 'string' }).default(
insertedAt: timestamp('inserted_at', timestampCfg).default(
sql`CURRENT_TIMESTAMP`,
),
pretranspose: integer('pretranspose').default(0),
Expand All @@ -55,7 +56,7 @@ export const deletedSong = pgTable('deleted_song', {
id,
songIdString: char('song_id_string', { length: 20 }).unique(),
songId: integer('song_id').notNull(),
deletedAt: timestamp('last_modified', { mode: 'string' })
deletedAt: timestamp('last_modified', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
})
Expand All @@ -65,10 +66,10 @@ export const collection = pgTable('collection', {
idString: char('id_string', { length: 20 }).unique(),
slug: varchar('slug', { length: 256 }).notNull().unique(),
name: varchar('name', { length: 256 }).notNull(),
insertedAt: timestamp('inserted_at', { mode: 'string' })
insertedAt: timestamp('inserted_at', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
lastModified: timestamp('last_modified', { mode: 'string' })
lastModified: timestamp('last_modified', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
locked: boolean('locked').notNull().default(false),
Expand All @@ -80,7 +81,7 @@ export const deletedCollection = pgTable('deleted_collection', {
id,
collectionIdString: char('collection_id_string', { length: 20 }).unique(),
collectionId: integer('collection_id').notNull(),
deletedAt: timestamp('last_modified', { mode: 'string' })
deletedAt: timestamp('last_modified', timestampCfg)
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
})
Expand All @@ -101,5 +102,5 @@ export const session = pgTable('session', {
id,
token: char('token', { length: 30 }).unique().notNull(),
user: integer('user_id').notNull(), //.references(() => user.id),
expires: timestamp('expires', { mode: 'string' }).notNull(),
expires: timestamp('expires', timestampCfg).notNull(),
})

0 comments on commit c93b3dc

Please sign in to comment.