update for the db.ts
This commit is contained in:
parent
b737e87d9a
commit
f1e88d35ba
3 changed files with 30 additions and 1 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run src/index.ts",
|
"dev": "bun run src/index.ts",
|
||||||
|
"db:check": "bun run --env-file .env src/check.ts",
|
||||||
"typecheck": "tsgo --noEmit"
|
"typecheck": "tsgo --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
28
packages/apn-relay/src/check.ts
Normal file
28
packages/apn-relay/src/check.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { sql } from "drizzle-orm"
|
||||||
|
import { db } from "./db"
|
||||||
|
import { env } from "./env"
|
||||||
|
import { delivery_log, device_registration } from "./schema.sql"
|
||||||
|
import { setup } from "./setup"
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
console.log(`[apn-relay] DB host: ${env.DATABASE_HOST}`)
|
||||||
|
|
||||||
|
await db.execute(sql`SELECT 1`)
|
||||||
|
console.log("[apn-relay] DB connection OK")
|
||||||
|
|
||||||
|
await setup()
|
||||||
|
console.log("[apn-relay] Setup migration OK")
|
||||||
|
|
||||||
|
const [a] = await db.select({ value: sql<number>`count(*)` }).from(device_registration)
|
||||||
|
const [b] = await db.select({ value: sql<number>`count(*)` }).from(delivery_log)
|
||||||
|
|
||||||
|
console.log(`[apn-relay] device_registration rows: ${Number(a?.value ?? 0)}`)
|
||||||
|
console.log(`[apn-relay] delivery_log rows: ${Number(b?.value ?? 0)}`)
|
||||||
|
console.log("[apn-relay] DB check passed")
|
||||||
|
}
|
||||||
|
|
||||||
|
run().catch((err) => {
|
||||||
|
console.error("[apn-relay] DB check failed")
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
|
@ -8,4 +8,4 @@ const client = new Client({
|
||||||
password: env.DATABASE_PASSWORD,
|
password: env.DATABASE_PASSWORD,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const db = drizzle(client)
|
export const db = drizzle({ client })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue