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 registrationmaster
parent
f019e4114f
commit
8763a426e0
|
|
@ -4,9 +4,13 @@ import { users, User, NewUser } from "../shared/schema";
|
||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import fs from "node:fs";
|
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)
|
// 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
|
// Ensure data directory exists
|
||||||
const dbDir = path.dirname(dbPath);
|
const dbDir = path.dirname(dbPath);
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,19 @@ import express from 'express';
|
||||||
import type { Express } from 'express';
|
import type { Express } from 'express';
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
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) {
|
export function serveStatic(app: Express) {
|
||||||
// In production, dist/public is at the same level as index.cjs
|
// In production CJS bundle, __dirname points to the compiled file
|
||||||
const distPath = path.resolve(__dirname, "..", "public");
|
// 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)) {
|
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(
|
throw new Error(
|
||||||
`Could not find the build directory: ${distPath}, make sure to build the client first`,
|
`Could not find the build directory: ${distPath}, make sure to build the client first`,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
// GammaDesk shared data model
|
// GammaDesk shared data model
|
||||||
// ORATS-style options analytics types + Drizzle tables for auth.
|
// ORATS-style options analytics types + Drizzle tables for auth.
|
||||||
// Database: PostgreSQL
|
// Database: SQLite (PostgreSQL migration planned later)
|
||||||
|
|
||||||
import { z } from "zod";
|
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", {
|
export const users = sqliteTable("users", {
|
||||||
id: serial("id").primaryKey(),
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||||
name: text("name").notNull(),
|
name: text("name").notNull(),
|
||||||
email: text("email").notNull().unique(),
|
email: text("email").notNull().unique(),
|
||||||
passwordHash: text("password_hash").notNull(),
|
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;
|
export type User = typeof users.$inferSelect;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue