diff --git a/drizzle/0000_neat_marvel_boy.sql b/drizzle/0000_rapid_turbo.sql similarity index 67% rename from drizzle/0000_neat_marvel_boy.sql rename to drizzle/0000_rapid_turbo.sql index b87c2f2..88dd2e4 100644 --- a/drizzle/0000_neat_marvel_boy.sql +++ b/drizzle/0000_rapid_turbo.sql @@ -3,8 +3,8 @@ CREATE TABLE `entry` ( `name` text NOT NULL, `href` text NOT NULL, `finished` integer DEFAULT false NOT NULL, - `created_at` integer DEFAULT (unixepoch('subsec') NOT NULL, - `updated_at` integer DEFAULT (unixepoch('subsec') NOT NULL + `created_at` integer DEFAULT (unixepoch('subsec')) NOT NULL, + `updated_at` integer DEFAULT (unixepoch('subsec')) NOT NULL ); --> statement-breakpoint CREATE UNIQUE INDEX `entry_name_unique` ON `entry` (`name`); \ No newline at end of file diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index bead0bc..c911c58 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,7 +1,7 @@ { "version": "6", "dialect": "sqlite", - "id": "5b7c56dc-4c5d-444a-9c66-9da5c7e06977", + "id": "034dc823-0bad-47de-9b5e-4858f89517be", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { "entry": { @@ -42,7 +42,7 @@ "primaryKey": false, "notNull": true, "autoincrement": false, - "default": "(unixepoch('subsec')" + "default": "(unixepoch('subsec'))" }, "updated_at": { "name": "updated_at", @@ -50,7 +50,7 @@ "primaryKey": false, "notNull": true, "autoincrement": false, - "default": "(unixepoch('subsec')" + "default": "(unixepoch('subsec'))" } }, "indexes": { diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 07bebd2..b23e935 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "6", - "when": 1743898098259, - "tag": "0000_neat_marvel_boy", + "when": 1743898653227, + "tag": "0000_rapid_turbo", "breakpoints": true } ] diff --git a/src/db/index.ts b/src/db/index.ts index 5740a53..c021b00 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,7 +1,7 @@ import { Database } from 'bun:sqlite'; import { env } from 'bun'; import { drizzle } from 'drizzle-orm/bun-sqlite'; -import { migrate } from 'drizzle-orm/bun-sqlite/migrator'; +// import { migrate } from 'drizzle-orm/bun-sqlite/migrator'; import { createWrappedTimer } from '../wrapped-timer'; function initDb() { @@ -25,10 +25,10 @@ function vacuumDb() { } if (global.db === undefined || global.drizzleDB === undefined) { - global.db = new Database(`${env.SQLITE_DB_PATH}/${env.SQLITE_DB_NAME}`, { create: true }); + global.db = new Database(`${env.SQLITE_DB_PATH}/${env.SQLITE_DB_NAME}`, { create: true, strict: true }); initDb(); global.drizzleDB = drizzle(global.db); - migrate(global.drizzleDB, { migrationsFolder: './drizzle' }); + // migrate(global.drizzleDB, { migrationsFolder: './drizzle' }); } const incrementalVacuumInterval = 1000 * 30; // 30 seconds diff --git a/src/db/schema.ts b/src/db/schema.ts index d3d4ca0..b473d39 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -3,11 +3,11 @@ import { index, integer, primaryKey, sqliteTable, text } from 'drizzle-orm/sqlit const createdAt = integer('created_at', { mode: 'timestamp_ms' }) .notNull() - .default(sql`(unixepoch('subsec')`) + .default(sql`(unixepoch('subsec'))`) .$defaultFn(() => new Date()); const updatedAt = integer('updated_at', { mode: 'timestamp_ms' }) .notNull() - .default(sql`(unixepoch('subsec')`) + .default(sql`(unixepoch('subsec'))`) .$onUpdateFn(() => new Date()); export const entry = sqliteTable( diff --git a/src/server.ts b/src/server.ts index 762f515..9754b46 100644 --- a/src/server.ts +++ b/src/server.ts @@ -6,6 +6,7 @@ import sitemapTxt from './static/sitemap.txt'; import icon from './static/favicon.png' with { type: 'file' }; import { entry } from "./db/schema"; import { desc, eq } from "drizzle-orm"; +import { drizzleDB } from "./db"; const favicon = await Bun.file(icon).bytes(); const development = env.NODE_ENV !== 'production'; @@ -138,9 +139,11 @@ async function getEntryFromReq(req: Request) { } function isAuthenticated(req: Request) { - const bearer = req.headers.get('bearer'); - if (!bearer) return false; - + const auth = req.headers.get('authorization'); + if (!auth) return false; + const [type, bearer] = auth.split(' '); + if (type !== 'Bearer') return false; + // Check if the token is valid return bearer === env.BEARER_TOKEN; }