Skip to content

Commit 77ad6ef

Browse files
committed
Auth and Database Schema Overhaul
1 parent 7a2cbf4 commit 77ad6ef

60 files changed

Lines changed: 1680 additions & 537 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ XAI_API_KEY=****
44
ANTHROPIC_API_KEY=****
55
POSTGRES_URL=postgres://postgres:postgres@localhost:5432/chatbot
66
FILEBASE_URL=file:node_modules/local.db
7-
USE_FILE_SYSTEM_DB=true
7+
USE_FILE_SYSTEM_DB=true
8+
AUTH_SECRET="****" # Added by `npx auth`. Read more: https://cli.authjs.dev

drizzle.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const url = process.env.USE_FILE_SYSTEM_DB
1010
: process.env.POSTGRES_URL!;
1111

1212
const schema = process.env.USE_FILE_SYSTEM_DB
13-
? "./src/lib/db/schema.sqlite.ts"
14-
: "./src/lib/db/schema.pg.ts";
13+
? "./src/lib/db/sqlite/schema.sqlite.ts"
14+
: "./src/lib/db/pg/schema.pg.ts";
1515

1616
const out = process.env.USE_FILE_SYSTEM_DB
1717
? "./src/lib/db/migrations/sqlite"

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
"type": "module",
88
"scripts": {
99
"dev": "pnpm initial:check && next dev --turbopack",
10-
"build": "rimraf .next && pnpm next build",
10+
"build": "next build",
1111
"start": "next start",
1212
"test": "vitest",
13-
"lint:next": "next lint",
14-
"lint:biome": "biome lint --write --unsafe ./src",
15-
"lint": "pnpm lint:biome && pnpm lint:next",
13+
"lint": "next lint && biome lint --write --unsafe",
14+
"lint:fix": "next lint --fix && biome lint --write --unsafe",
1615
"format": "biome format --write",
1716
"check-types": "tsc --noEmit",
1817
"initial:check": "tsx scripts/flag.ts check",
@@ -25,7 +24,7 @@
2524
"db:reset": "drizzle-kit drop && drizzle-kit push",
2625
"db:push": "drizzle-kit push",
2726
"db:studio": "drizzle-kit studio",
28-
"db:migrate": "tsx src/lib/db/migrate.sqlite.ts",
27+
"db:migrate": "tsx scripts/db-migrate.ts",
2928
"db:pull": "drizzle-kit pull",
3029
"db:check": "drizzle-kit check"
3130
},
@@ -58,6 +57,7 @@
5857
"@tiptap/starter-kit": "^2.11.7",
5958
"@tiptap/suggestion": "^2.11.7",
6059
"ai": "^4.3.10",
60+
"bcrypt-ts": "^7.0.0",
6161
"chokidar": "^4.0.3",
6262
"class-variance-authority": "^0.7.1",
6363
"clsx": "^2.1.1",
@@ -72,6 +72,7 @@
7272
"lucide-react": "^0.486.0",
7373
"nanoid": "^5.1.5",
7474
"next": "15.2.4",
75+
"next-auth": "5.0.0-beta.27",
7576
"next-themes": "^0.4.6",
7677
"ollama-ai-provider": "^1.2.0",
7778
"pg": "^8.15.6",
@@ -106,5 +107,8 @@
106107
"vite-tsconfig-paths": "^5.1.4",
107108
"vitest": "^3.1.2"
108109
},
109-
"packageManager": "pnpm@10.2.1"
110+
"packageManager": "pnpm@10.2.1",
111+
"engines": {
112+
"node": ">=20.0.0"
113+
}
110114
}

pnpm-lock.yaml

Lines changed: 85 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/pf.png

14.2 KB
Loading

scripts/db-migrate.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { config } from "dotenv";
2+
import logger from "logger";
3+
import { colorize } from "consola/utils";
4+
5+
config();
6+
7+
let promise: Promise<any>;
8+
if (process.env.USE_FILE_SYSTEM_DB) {
9+
promise = import("lib/db/sqlite/migrate.sqlite");
10+
} else {
11+
promise = import("lib/db/pg/migrate.pg");
12+
}
13+
14+
await promise
15+
.then(() => {
16+
logger.info("🚀 DB Migration completed");
17+
})
18+
.catch((err) => {
19+
logger.error(err);
20+
21+
logger.warn(
22+
`
23+
${colorize("red", "🚨 Migration failed due to incompatible schema.")}
24+
25+
❗️DB Migration failed – incompatible schema detected.
26+
27+
This version introduces a complete rework of the database schema.
28+
As a result, your existing database structure may no longer be compatible.
29+
30+
**To resolve this:**
31+
32+
1. Drop all existing tables in your database.
33+
2. Then run the following command to apply the latest schema:
34+
35+
36+
${colorize("green", "pnpm db:migrate")}
37+
38+
**Note:** This schema overhaul lays the foundation for more stable updates moving forward.
39+
You shouldn’t have to do this kind of reset again in future releases.
40+
41+
Need help? Open an issue on GitHub 🙏
42+
`.trim(),
43+
);
44+
45+
process.exit(1);
46+
});

scripts/flag.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { existsSync, mkdirSync } from "node:fs";
33
import logger from "logger";
44
import { colorize } from "consola/utils";
55

6-
const VERSION = "0.0.6";
6+
export const FLAG_VERSION = "1.0.0";
77

88
const CACHE_PATH = join(process.cwd(), "node_modules/.mcp-chatbot-cache");
99

10-
const flagPath = join(CACHE_PATH, VERSION);
10+
const flagPath = join(CACHE_PATH, FLAG_VERSION);
1111

1212
const flagCheck = () => {
1313
if (existsSync(flagPath)) {
@@ -31,7 +31,7 @@ if (command === "generate") {
3131
} else {
3232
if (!flagCheck()) {
3333
logger.error(
34-
`${colorize("cyan", "🔄 UPDATE REQUIRED")} - ${colorize("yellow", `Version ${VERSION}`)}:\n\n👇🏻 Please run the following commands for proper operation:\n\n${colorize("green", "pnpm initial")}`,
34+
`${colorize("cyan", "🔄 UPDATE REQUIRED")} - ${colorize("yellow", `Version ${FLAG_VERSION}`)}:\n\n👇🏻 Please run the following commands for proper operation:\n\n${colorize("green", "pnpm initial")}`,
3535
);
3636
process.exit(1);
3737
}

src/app/(auth)/layout.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Think } from "ui/think";
2+
3+
export default function AuthLayout({
4+
children,
5+
}: { children: React.ReactNode }) {
6+
return (
7+
<main className="relative w-full flex flex-col h-screen">
8+
<div className="flex-1">
9+
<div className="flex min-h-screen w-full">
10+
<div className="hidden lg:flex lg:w-1/2 bg-muted border-r flex-col p-18">
11+
<h1 className="text-xl font-semibold flex items-center gap-3">
12+
<Think />
13+
14+
<span>Chat Bot</span>
15+
</h1>
16+
<div className="flex-1" />
17+
<p className=" mb-4 text-muted-foreground">
18+
Welcome to MCP Chat Bot. Sign in to experience our
19+
<span className="text-foreground ml-1">
20+
AI-powered conversational tools.
21+
</span>
22+
</p>
23+
</div>
24+
25+
<div className="w-full lg:w-1/2 p-6">{children}</div>
26+
</div>
27+
</div>
28+
</main>
29+
);
30+
}

0 commit comments

Comments
 (0)