* feat(cloud): implement Postgres DB adapter, fix static build crashes, and containerize NextAuth/Stripe integrations
* test(marketplace): fix mocks and assertions for multi-tenant Postgres architecture
* feat: rsa jwt license key verification and state integration
* feat: add internal workspace validation route for Edge Functions
* refactor: clean up hub routes and finalize db proxy/adapter for multi-tenant cloud deploy
* feat(cloud): finalize multi-tenant Prisma extensions and workspace routing
* fix(db): correct Prisma 7 better-sqlite3 adapter initialization [Patch]
- update better-sqlite3 adapter instantiation to use configuration object ({ url }) required by Prisma 7 instead of raw Database instance [Patch]
- fix PrismaClientConstructorValidationError by generating client with adapter support [Patch]
* fix(auth): support dynamic origins for local proxies and multi-tenant subdomains [Patch]
- prioritize forwarded headers and request host over hardcoded envOrigin in getRequestOrigin to support subdomain routing [Patch]
- allow ALLOWED_DEV_ORIGIN in marketplace install redirect checks to fix local network development login flows [Patch]
* fix(marketplace): enable dynamic CORS reflection for marketplace API [Patch]
- remove explicit origin array, replacing with origin header reflection to allow marketplace hosted on any domain or local IP [Patch]
- remove global wildcard CORS headers from next.config.ts to harden security against broader app injection [Patch]
* feat(db): create initial postgresql migration
* refactor(db): update remaining files for postgresql
* feat(db): unify database adapter to PostgreSQL-only [Minor]
- replace SQLite adapter with PostgreSQL PrismaPg [Minor]
- remove better-sqlite3 dependencies [Patch]
- finalize docs and implementation plan [Patch]
* fix: resolve prisma client generation and script execution issues with tsx and type module
* feat(db): port tenant isolation logic to new PostgreSQL adapter
* docs: add rule for transparent and narrated agent actions
* BREAKING CHANGE(core): migrate to PostgreSQL and add auto-migration pipeline [Major]
- unified database adapter to exclusively use PostgreSQL [Major]
- implement auto-migration pipeline to pipe legacy SQLite data to Postgres [Major]
- add sqlite to runner stage to support extraction pipeline [Patch]
* feat(core): migrate to Prisma 7 and unify PostgreSQL architecture [Minor]
- removed legacy Prisma SQLite driver and all Better-Sqlite dependencies [Minor]
- updated schema to utilize purely postgresql providers [Patch]
- modified migration scripts to seamlessly convert local sqlite DBs to PostgreSQL containers using keinos/sqlite3 [Minor]
- updated deployment scripts, Coolify pipelines, and Nginx proxy support [Patch]
- injected Prisma Client Extensions for multi-tenant Row Level Security isolation [Minor]
- stabilized PrismaClient initialization utilizing the official adapter-pg runtime pattern [Patch]
- bumped version to 2.1.0
* fix(core): resolve TypeScript compilation errors for CI [Patch]
- fixed NextResponse.json() 3-arg calls to use 2-arg ResponseInit form [Patch]
- replaced invalid 'developer' TrustTier with 'unverified' in parseWwvManifest and load-unpacked route [Patch]
- removed non-existent pluginManager.hotReload() call in DevModeSubscriber, replaced with disable/reload cycle [Patch]
- updated Stripe API version from '2024-04-10' to '2026-04-22.dahlia' to match installed SDK [Patch]
- excluded local-scripts/ from tsconfig to prevent debug scripts from breaking CI [Patch]
* fix(ci): resolve pnpm version conflict in GitHub Actions [Patch]
- removed explicit version: 9 from pnpm/action-setup@v4 — v4 auto-reads packageManager from package.json [Patch]
- updated build job DATABASE_URL from SQLite to PostgreSQL format [Patch]
* fix(docker): add explicit Prisma generator output path for Docker builds [Patch]
- Prisma 7 changed default output location, causing COPY --from=builder to fail
- added output = '../src/generated/prisma' to generator block for consistency
* fix(prisma): update client import path and resolve CI type errors [Patch]
- updated PrismaClient import in db.ts to point to custom generated output path
- resolved implicit 'any' error in marketplace check-updates route
- verified clean local build with tsc --noEmit
* chore(deps): sync Prisma versions to 7.6.0 [Patch]
130 lines
4.7 KiB
JavaScript
130 lines
4.7 KiB
JavaScript
import { execSync } from "child_process";
|
|
import fs from "fs";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import pg from "pg";
|
|
const { Pool } = pg;
|
|
|
|
const SQLITE_DB_PATH = "./data/wwv.db";
|
|
const MIGRATED_MARKER = "./data/wwv.db.migrated";
|
|
|
|
async function run() {
|
|
if (!fs.existsSync(SQLITE_DB_PATH)) {
|
|
// No SQLite database found, nothing to migrate
|
|
return;
|
|
}
|
|
|
|
if (fs.existsSync(MIGRATED_MARKER)) {
|
|
console.log("[migration] SQLite database already migrated. Skipping.");
|
|
return;
|
|
}
|
|
|
|
console.log("[migration] Legacy SQLite database detected. Initiating migration to PostgreSQL...");
|
|
|
|
// Initialize Prisma client connecting to PostgreSQL natively via adapter
|
|
const connectionString = process.env.DATABASE_URL;
|
|
if (!connectionString) {
|
|
console.error("[migration] DATABASE_URL environment variable is missing.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const pool = new Pool({ connectionString });
|
|
const adapter = new PrismaPg(pool);
|
|
const prisma = new PrismaClient({ adapter });
|
|
|
|
try {
|
|
await prisma.$connect();
|
|
|
|
const tablesToMigrate = [
|
|
{ sqlite: "users", prisma: prisma.user, key: "id" },
|
|
{ sqlite: "workspaces", prisma: prisma.workspace, key: "id" },
|
|
{ sqlite: "workspace_members", prisma: prisma.workspaceMember, key: "id" },
|
|
{ sqlite: "favorites", prisma: prisma.favorite, key: "id" },
|
|
{ sqlite: "installed_plugins", prisma: prisma.installedPlugin, key: "id" },
|
|
{ sqlite: "settings", prisma: prisma.setting, key: "id" }
|
|
];
|
|
|
|
for (const table of tablesToMigrate) {
|
|
console.log(`[migration] Migrating table: ${table.sqlite}...`);
|
|
let rowsJson = "[]";
|
|
try {
|
|
// Read data from SQLite
|
|
const isWindows = process.platform === "win32";
|
|
const cmd = isWindows
|
|
? `docker run --rm -v "${process.cwd().replace(/\\/g, '/')}/data:/data" keinos/sqlite3 sqlite3 --json /data/wwv.db "SELECT * FROM ${table.sqlite};"`
|
|
: `sqlite3 --json ${SQLITE_DB_PATH} "SELECT * FROM ${table.sqlite};"`;
|
|
|
|
const output = execSync(cmd, { encoding: "utf-8", stdio: ['pipe', 'pipe', 'ignore'] });
|
|
if (output && output.trim()) {
|
|
rowsJson = output;
|
|
}
|
|
} catch (err) {
|
|
// Table might not exist in SQLite (e.g., workspaces was newly added), that's fine
|
|
console.log(`[migration] Skipping table ${table.sqlite} (might not exist in legacy DB).`);
|
|
continue;
|
|
}
|
|
|
|
const rows = JSON.parse(rowsJson);
|
|
if (rows.length === 0) {
|
|
continue;
|
|
}
|
|
|
|
console.log(`[migration] Found ${rows.length} rows in ${table.sqlite}. Insertions...`);
|
|
let inserted = 0;
|
|
for (const row of rows) {
|
|
// Handle boolean fields which are 1/0 in SQLite
|
|
if (table.sqlite === "installed_plugins" && "enabled" in row) {
|
|
row.enabled = row.enabled === 1;
|
|
}
|
|
|
|
// Handle dates which are strings/numbers in SQLite
|
|
const dateFields = ["createdAt", "updatedAt", "lastSeen", "installedAt", "joinedAt"];
|
|
for (const field of dateFields) {
|
|
if (row[field]) {
|
|
// SQLite dates might be stored as Unix timestamps or strings
|
|
// If it's a number, it could be seconds or milliseconds. Prisma stores ms.
|
|
if (typeof row[field] === "number") {
|
|
// If it's in seconds (typical Unix timestamp), multiply by 1000
|
|
// A timestamp in 2024 is around 1.7e9, in ms it's 1.7e12
|
|
const isSeconds = row[field] < 1e11;
|
|
row[field] = new Date(isSeconds ? row[field] * 1000 : row[field]);
|
|
} else {
|
|
row[field] = new Date(row[field]);
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
// All these tables have "id" as the primary key.
|
|
const exists = await table.prisma.findUnique({
|
|
where: { id: row.id }
|
|
});
|
|
|
|
if (!exists) {
|
|
await table.prisma.create({
|
|
data: row
|
|
});
|
|
inserted++;
|
|
}
|
|
} catch (err) {
|
|
console.error(`[migration] Failed to insert row into ${table.sqlite}: ${err.message}`);
|
|
}
|
|
}
|
|
console.log(`[migration] Inserted ${inserted} new rows into PostgreSQL table ${table.sqlite}.`);
|
|
}
|
|
|
|
// Mark as migrated
|
|
fs.writeFileSync(MIGRATED_MARKER, new Date().toISOString(), "utf8");
|
|
console.log("[migration] SQLite to PostgreSQL migration completed successfully!");
|
|
console.log("[migration] Note: You can safely delete ./data/wwv.db now.");
|
|
|
|
} catch (err) {
|
|
console.error("[migration] Fatal error during migration:", err);
|
|
process.exit(1);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
run();
|