AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat: reserve postgres storage backend
tianma-if8df4a9d5cc7a
diff --git a/apps/api/src/self-hosted-storage-adapter.ts b/apps/api/src/self-hosted-storage-adapter.tsindex 0a4fc16d..04ac1304 100644--- a/apps/api/src/self-hosted-storage-adapter.ts+++ b/apps/api/src/self-hosted-storage-adapter.ts@@ -4,6 +4,7 @@ import type {BlobObjectAdapter,BlobStoreAdapter,DatabaseAdapter,+ RelationalDatabaseDialect,StorageAdapter,} from "./storage-contract";@@ -17,6 +18,8 @@ export type SqliteDatabaseLike = {transaction: (callback: () => void) => () => unknown;};+export const SELF_HOSTED_DATABASE_DIALECT: RelationalDatabaseDialect = "sqlite";+class SqlitePreparedStatement {constructor(private readonly sqlite: SqliteDatabaseLike,diff --git a/apps/api/src/storage-contract.ts b/apps/api/src/storage-contract.tsindex 55ec86a9..65e770b3 100644--- a/apps/api/src/storage-contract.ts+++ b/apps/api/src/storage-contract.ts@@ -35,6 +35,21 @@ export type StorageAdapter = {resources: BlobStoreAdapter;};+/** Database engines that a self-hosted deployment may select. */+export type RelationalDatabaseDialect = "sqlite" | "postgresql";++/**+ * Future driver-neutral relational contract. The current API still consumes+ * the D1-compatible DatabaseAdapter above; this contract prevents a future+ * PostgreSQL implementation from leaking driver-specific calls into routes.+ */+export type RelationalDatabaseAdapter = {+ readonly dialect: RelationalDatabaseDialect;+ query<T>(sql: string, parameters?: readonly unknown[]): Promise<readonly T[]>;+ execute(sql: string, parameters?: readonly unknown[]): Promise<void>;+ transaction<T>(callback: (database: RelationalDatabaseAdapter) => Promise<T>): Promise<T>;+};+/** Cloudflare's native Worker bindings, used only by the platform adapter. */export type CloudflareStorageBindings = {DB: DatabaseAdapter;@@ -48,4 +63,12 @@ export type SelfHostedStorageConfig = {dataDirectory: string;databaseFile: string;resourcesDirectory: string;+ databaseDialect?: RelationalDatabaseDialect;+};++/** Configuration reserved for a future PostgreSQL-backed deployment. */+export type PostgreSQLStorageConfig = {+ databaseUrl: string;+ schema?: string;+ poolSize?: number;};diff --git a/docs/self-hosting-architecture.md b/docs/self-hosting-architecture.mdindex dd9a7039..6bd9db5d 100644--- a/docs/self-hosting-architecture.md+++ b/docs/self-hosting-architecture.md@@ -21,6 +21,12 @@ The shared self-hosted configuration shape is also defined as`SelfHostedStorageConfig`, with one application data directory, one SQLitedatabase file, and one attachment directory.+PostgreSQL is reserved as a second relational backend through the+driver-neutral `RelationalDatabaseAdapter` and `PostgreSQLStorageConfig`+contracts. It is intentionally not implemented yet. SQLite remains the+default self-hosted database; PostgreSQL will be useful for larger teams,+higher write concurrency, and external database operations.+## Intended Docker shapeThe first supported container deployment should be a single application@@ -37,6 +43,11 @@ The initial self-hosted adapter should preserve the existing SQLite schema andobject keys currently stored in `resources.object_key`; the implementation mayuse a local filesystem first and add an S3-compatible backend later.+When PostgreSQL is implemented, it must introduce an explicit SQL dialect and+migration set for PostgreSQL-specific full-text search and transaction+behavior. It must not make the current SQLite/D1 migration files silently+ambiguous.+## Compatibility requirements- Keep `/api/*`, `/mcp`, `/api/openapi.json`, and `/api/health` unchanged.diff --git a/docs/self-hosting-architecture.zh-CN.md b/docs/self-hosting-architecture.zh-CN.mdindex 553b9259..2f4b5fc3 100644--- a/docs/self-hosting-architecture.zh-CN.md+++ b/docs/self-hosting-architecture.zh-CN.md@@ -19,6 +19,11 @@ Cloudflare SDK 类型。目前的具体实现位于共享的自托管配置结构也已定义为 `SelfHostedStorageConfig`,包含统一的应用数据目录、SQLite 数据库文件和附件目录。+PostgreSQL 已通过与驱动无关的 `RelationalDatabaseAdapter` 和+`PostgreSQLStorageConfig` 契约预留为第二种关系数据库后端,但当前尚未实现。+SQLite 仍是自托管默认数据库;未来 PostgreSQL 更适合较大团队、更高写入并发+以及独立数据库运维场景。+## 计划中的 Docker 形态第一版正式支持的容器部署应为单容器应用,并挂载两个持久化目录:@@ -33,6 +38,9 @@ EdgeEver 容器`resources.object_key` 中保存的不透明对象键,初版可以使用本地文件系统,后续再增加 S3 兼容存储。+未来实现 PostgreSQL 时,必须明确处理 SQL 方言以及 PostgreSQL 专用的全文搜索+和事务行为,并提供独立迁移策略,不能让现有 SQLite/D1 migration 文件产生歧义。+## 兼容性要求- 保持 `/api/*`、`/mcp`、`/api/openapi.json` 和 `/api/health` 不变。diff --git a/tests/storage-adapter.test.ts b/tests/storage-adapter.test.tsindex dccc50bf..e0a37766 100644--- a/tests/storage-adapter.test.ts+++ b/tests/storage-adapter.test.ts@@ -3,6 +3,7 @@ import { mkdtemp, readFile, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { createCloudflareStorageAdapter } from "../apps/api/src/cloudflare-storage-adapter";import { createSelfHostedStorageAdapter } from "../apps/api/src/self-hosted-storage-adapter";+import { SELF_HOSTED_DATABASE_DIALECT } from "../apps/api/src/self-hosted-storage-adapter";describe("storage adapter", () => {test("wraps Cloudflare bindings without changing their identity", () => {@@ -14,6 +15,10 @@ describe("storage adapter", () => {expect(adapter.resources).toBe(resources);});+ test("keeps the self-hosted database dialect explicit", () => {+ expect(SELF_HOSTED_DATABASE_DIALECT).toBe("sqlite");+ });+test("stores attachments in a persistent filesystem directory", async () => {const directory = await mkdtemp(`${tmpdir()}/edgeever-storage-`);const sqlite = {