From 8763a426e0e6653fa2f4bc333f48f7547bf910a5 Mon Sep 17 00:00:00 2001 From: isnowglobal-admin Date: Sat, 13 Jun 2026 19:24:34 -0400 Subject: [PATCH] Fix: Switch schema from PostgreSQL to SQLite for user registration - Use sqliteTable/integer instead of pgTable/serial - Fix Drizzle ORM compatibility with better-sqlite3 driver - This was causing silent failures on user registration --- server/db.ts | 6 +++++- server/static.ts | 21 ++++++++++----------- shared/schema.ts | 12 ++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/server/db.ts b/server/db.ts index ed4358a..dfe6dba 100644 --- a/server/db.ts +++ b/server/db.ts @@ -4,9 +4,13 @@ import { users, User, NewUser } from "../shared/schema"; import Database from "better-sqlite3"; import path from "node:path"; import fs from "node:fs"; +import { fileURLToPath } from "node:url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); // Use SQLite for production (PostgreSQL migration later) -const dbPath = path.resolve(__dirname || ".", "..", "data.db"); +const dbPath = path.resolve(__dirname, "..", "data.db"); // Ensure data directory exists const dbDir = path.dirname(dbPath); diff --git a/server/static.ts b/server/static.ts index bcc33b8..943aed5 100644 --- a/server/static.ts +++ b/server/static.ts @@ -2,20 +2,19 @@ import express from 'express'; import type { Express } from 'express'; import fs from "node:fs"; import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); export function serveStatic(app: Express) { - // In production, dist/public is at the same level as index.cjs - const distPath = path.resolve(__dirname, "..", "public"); + // In production CJS bundle, __dirname points to the compiled file + // so we check both the bundle-relative path and cwd + const bundleDistPath = path.resolve(__dirname, "..", "public"); + const cwdDistPath = path.resolve(process.cwd(), "dist", "public"); + const distPath = fs.existsSync(cwdDistPath) ? cwdDistPath : bundleDistPath; + if (!fs.existsSync(distPath)) { - // Fallback: check cwd - const cwdPath = path.resolve(process.cwd(), "dist", "public"); - if (fs.existsSync(cwdPath)) { - app.use(express.static(cwdPath)); - app.use("/{*path}", (_req, res) => { - res.sendFile(path.resolve(cwdPath, "index.html")); - }); - return; - } throw new Error( `Could not find the build directory: ${distPath}, make sure to build the client first`, ); diff --git a/shared/schema.ts b/shared/schema.ts index d4cf8fe..f3c2dd9 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -1,20 +1,20 @@ // GammaDesk shared data model // ORATS-style options analytics types + Drizzle tables for auth. -// Database: PostgreSQL +// Database: SQLite (PostgreSQL migration planned later) import { z } from "zod"; -import { pgTable, text, serial, timestamp, pgEnum } from "drizzle-orm/pg-core"; +import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"; // --------------------------------------------------------------------------- -// Auth - Users table (Drizzle + PostgreSQL) +// Auth - Users table (Drizzle + SQLite) // --------------------------------------------------------------------------- -export const users = pgTable("users", { - id: serial("id").primaryKey(), +export const users = sqliteTable("users", { + id: integer("id").primaryKey({ autoIncrement: true }), name: text("name").notNull(), email: text("email").notNull().unique(), passwordHash: text("password_hash").notNull(), - createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(), + createdAt: text("created_at").default(new Date().toISOString()), }); export type User = typeof users.$inferSelect;