Skip to content

chore(db): PostgreSQL 迁移统一分支 - #299

Draft
cropflre wants to merge 997 commits into
mainfrom
pg-migration-unified
Draft

chore(db): PostgreSQL 迁移统一分支#299
cropflre wants to merge 997 commits into
mainfrom
pg-migration-unified

Conversation

@cropflre

@cropflre cropflre commented Jul 15, 2026

Copy link
Copy Markdown
Owner

目的

所有未完成的 PostgreSQL 迁移统一在 pg-migration-unified 推进。PR 继续保持 Draft;当前仍为 PostgreSQL runtime-only,不宣称整个项目已可生产切换。

  • businessRoutesReady = false
  • PostgreSQL Note Transfer 已完成统一异步编排
  • SQLite → PostgreSQL 已完成预检、可恢复复制、独立校验、空/非空目标 rollback、并发修改保护、规模化演练与最终报告
  • 搜索/向量、PostgreSQL 备份恢复与正式部署切换仍未完成

最新代码基线

  • main@69b277133fe5aeae0e7b9d9dc8c6960373467c61
  • release/v1.4.6@243438d6dfcefa80b0ca07a0a58d7a1e3b4b4708
  • 当前迁移分支:pg-migration-unified@93aeff98c369ca0b187056e3754ab951d99c6449
  • 当前比较:release/v1.4.6 behind_by = 0ahead_by = 910

发布代码使用 merge commit 同步,不 rebase、不 force push:

本轮同步包含冲突副本/草稿安全、latest-only save queue、note sync review、图片导出修复脚本与 Android 发版断言调整。

已完成的 PostgreSQL Runtime

Notes

已覆盖列表、详情、创建、更新、移动、排序、回收站、恢复、永久删除及删除副作用。

Knowledge Tree

已覆盖 scope listing、shared roots、创建、更新、移动、排序、删除、恢复、权限、历史、文件夹密码与 unlock。

Note Transfer(#249

preview
→ prepare
→ attachment staging
→ atomic target commit
→ audit/webhook/realtime effects
→ move source deletion
→ completed

对应 immutable migrations:0016~0022

SQLite → PostgreSQL 数据迁移(#251

第一切片:预检与持久化基础

覆盖只读 source inspection、备份一致性、目标 schema/非空检查、依赖排序、幂等计划、table/batch checkpoint、lease 与 expired lease takeover。

第二切片:可恢复复制与独立校验

覆盖冻结备份、主键 keyset cursor、事务化 upsert/checkpoint、restart/resume、类型转换、自引用修复、identity sequence、checksum、copy-time verify 与 independent verify。

第三切片:run-owned tracking 与空目标 rollback

覆盖 run-owned table/primary-key 记录、反向依赖 rollback、bounded interruption/resume、残留验证与幂等 replay。

第四切片:非空目标冲突与原值恢复

覆盖 abort / overwrite-with-backup 冲突策略、inserted / updated / unchanged 分类、类型安全 originalRow、精确 migratedRow、非空目标 verify、updated 恢复与迁移后并发修改保护。

第五切片:规模化演练与最终报告

完整演练链路:

apply
→ independent verify
→ rollback
→ post-rollback primary-key / row-count / checksum validation
→ PostgreSQL foreign-key orphan validation
→ final report persistence

新增:

  • medium deterministic fixture:600 条业务数据
  • large deterministic fixture:2,000 条业务数据
  • bounded apply / rollback passes,验证进程级 restart/resume
  • 同事务失败注入,验证业务行、ownership 与 checkpoint 一起回滚
  • 空目标完整演练
  • 非空目标 inserted / updated / unchanged / unrelated 数据恢复与保留演练
  • rollback 后逐表主键集合、行数与 canonical checksum 校验
  • PostgreSQL 外键孤儿检查
  • 最终 JSON report,写入指定文件并持久化到 migration run report
  • inserted / updated / unchanged / deleted / restored / conflict / failure 汇总
  • source/backup 只读 mtime 校验
  • 操作 runbook、磁盘空间建议与备份保留要求

Drill CLI:

DATABASE_URL='postgres://...' \
npm run migrate:sqlite-to-postgres:drill -- \
  --source /path/to/nowen-note.db \
  --backup /path/to/nowen-note.backup.db \
  --idempotency-key drill-2026-08-06 \
  --batch-size 200 \
  --max-batches-per-pass 10 \
  --max-rollback-batches-per-pass 10 \
  --report /secure/path/report.json

非空目标仍必须显式使用:

--allow-non-empty-target --conflict-policy overwrite-with-backup

相关验证

  • 预检 PR / 分支:30987878300 / 30988195159
  • 复制校验 PR / 分支:30990596984 / 30990807971
  • 空目标 rollback PR / 分支:30995951482 / 30996081772
  • 非空恢复实现 / PR / 分支:31015699237 / 31015931968 / 31016060887
  • 规模化演练实现:Run 31063726993 / Job 92496940323 / success
  • 规模化演练 PR 永久门禁:Run 31064027454 / Job 92497841936 / success

覆盖 PostgreSQL 16、TypeScript、Direct DB Audit、schema parity、migrations 0001~0025、空/非空目标 apply/verify/rollback、类型恢复、并发修改保护、失败注入、中/大型演练、两个 CLI contract 与 production bundle。

这里只确认相关 PostgreSQL 专用门禁,不宣称全仓所有无关历史 CI 均已完成。

#251 当前判断

迁移引擎的代码范围已基本覆盖:

  • 只读预检与冻结备份
  • 分批复制、幂等与断点续跑
  • copy-time / independent verify
  • 空目标与非空目标 rollback
  • 原值快照与并发修改保护
  • 最终机器可读报告
  • 失败注入
  • 中型/大型数据集完整 drill
  • 操作 runbook

#251 暂时保持打开,等待真实 staging 数据演练证据归档或维护者确认正式收口。

为什么仍不能生产切换

仍依赖:

原始 SQLite 和冻结备份必须保留到迁移验证通过、rollback window 关闭且 PostgreSQL 备份完成独立恢复验证。

下一阶段

#251 的迁移引擎开发转入 #252

  1. 定义 PostgreSQL 搜索索引、FTS 和向量重建的唯一状态源
  2. 将搜索/向量构建纳入可恢复任务编排
  3. 完成逐笔记/逐 chunk 校验、断点续跑和重建报告
  4. 验证搜索结果、排序与权限过滤一致性
  5. 再进入 [PG-BACKUP-01] 重构 PostgreSQL 备份、恢复与灾难恢复链路 #253 备份恢复和 [PG-DEPLOY-01] 完成 PostgreSQL 正式部署、灰度切换与回滚演练 #254 部署切换

PR 继续保持 Draft。

cropflre commented Jul 16, 2026

Copy link
Copy Markdown
Owner Author

✅ PostgreSQL access/session validation passed

Validated branch: pg-migration-unified
Validated head: 9085b5453e6bd012aa60aab8229b63b0e43a1622
Run: 29554768794

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ✅ PostgreSQL schema parity
  • ✅ SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL access/session
  • ✅ Production backend bundle

@github-actions

Copy link
Copy Markdown
Contributor

❌ PostgreSQL unified validation failed

Validated branch: pg-migration-unified
Validated head: 1ccaabf709f98dd8bb4bec92fbe5bc976206f9b5
Run: 29510812222

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ❌ PostgreSQL schema parity(exit 1)
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle
  • ✅ PostgreSQL runtime resources packaged

Full diagnostic log is attached to the workflow run artifact.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PostgreSQL unified validation failed

Validated branch: pg-migration-unified
Validated head: 1ccaabf709f98dd8bb4bec92fbe5bc976206f9b5
Run: 29510954347

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ❌ PostgreSQL schema parity(exit 1)
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle
  • ✅ PostgreSQL runtime resources packaged

Full diagnostic log is attached to the workflow run artifact.

Copy link
Copy Markdown
Owner Author

/validate-pg-unified

@github-actions

Copy link
Copy Markdown
Contributor

❌ PostgreSQL unified validation failed

Validated branch: pg-migration-unified
Validated head: 3291f44ead31429e8d91f6fe1114704f5b64f5c2
Run: 29511494621

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ❌ PostgreSQL schema parity(exit 1)
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle
  • ✅ PostgreSQL runtime resources packaged

Full diagnostic log is attached to the workflow run artifact.

Copy link
Copy Markdown
Owner Author

/validate-pg-unified

@github-actions

Copy link
Copy Markdown
Contributor

✅ PostgreSQL unified validation passed

Validated branch: pg-migration-unified
Validated head: 542935f50c66255470d77c4d38495007ad970cd5
Run: 29511804247

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ✅ PostgreSQL schema parity
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle
  • ✅ PostgreSQL runtime resources packaged

Full diagnostic log is attached to the workflow run artifact.

Copy link
Copy Markdown
Owner Author

/validate-pg-unified

@github-actions

Copy link
Copy Markdown
Contributor

✅ PostgreSQL unified validation passed

Validated branch: pg-migration-unified
Validated head: b828395c3fd29ae901d52039ebc07ba39a6fdc1c
Run: 29512099142

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ✅ PostgreSQL schema parity
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle
  • ✅ PostgreSQL runtime resources packaged

Full diagnostic log is attached to the workflow run artifact.

Copy link
Copy Markdown
Owner Author

/validate-pg-unified-batch-b

@github-actions

Copy link
Copy Markdown
Contributor

✅ PostgreSQL Batch B validation passed

Validated branch: pg-migration-unified
Validated head: 6bba9a0da836c3fe1a4f3679aa78efbfaab2f231
Run: 29546608777

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ✅ PostgreSQL schema parity
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle

Copy link
Copy Markdown
Owner Author

/validate-pg-unified-batch-b

Copy link
Copy Markdown
Owner Author

/validate-pg-unified-batch-b-final

@github-actions

Copy link
Copy Markdown
Contributor

✅ PostgreSQL Batch B validation passed

Validated branch: pg-migration-unified
Validated head: 2b6b705efecedc69222c1bb434eb4a5343d6ff31
Run: 29546701987

  • ✅ npm ci
  • ✅ TypeScript
  • ✅ SQLite direct-access audit
  • ✅ PostgreSQL schema parity
  • ✅ Runtime / SQL dialect tests
  • ✅ Full SQLite regression
  • ✅ Real PostgreSQL tests
  • ✅ Production backend bundle

Copy link
Copy Markdown
Owner Author

#249 Batch B 已落地

最终 Head:2b6b705efecedc69222c1bb434eb4a5343d6ff31
验证 Run:29546774716

本轮直接在 pg-migration-unified 完成:

  • userAISettingsRepository async API 接入 Runtime Provider,并改为惰性解析 Adapter,避免模块导入早于 Runtime 初始化;
  • taskDependenciesRepository async API 接入 Runtime Provider;
  • taskProjectsRepository async API 接入 Runtime Provider;
  • 统一 SQLite / PostgreSQL 下项目统计字段的 number 返回;
  • 项目移除流程通过 executeStatements 保证解除任务关联与项目变更位于同一事务;
  • 新增 repository-batch-b-pg.test.ts,覆盖 AI 设置 upsert、项目统计/排序、任务依赖和事务行为;
  • Batch B 已加入常驻 pg-runtime.yml

最终验证全部通过:npm ci、TypeScript、SQLite direct-access audit、PostgreSQL schema parity、Runtime/SQL dialect、完整 SQLite 回归、真实 PostgreSQL 回归、生产 backend bundle。

一次性验证工作流已从 main 清理。PR 继续保持 Draft;#249 其余 Repository、#250 深度 Schema parity、#251#254 仍待推进。

Copy link
Copy Markdown
Owner Author

/validate-pg-permissions

2 similar comments

Copy link
Copy Markdown
Owner Author

/validate-pg-permissions

Copy link
Copy Markdown
Owner Author

/validate-pg-permissions

Copy link
Copy Markdown
Owner Author

本轮已直接在 pg-migration-unified 完成权限域 PostgreSQL 迁移:note ACL、workspace members、notebook members 的 async API 已改用 Runtime Provider;新增 0004_notebook_members_unique.sql 和真实 PG 测试 repository-permissions-pg.test.ts;新增常驻 pg-permissions.yml 门禁。最终验证 Head 2c04bc531409334479834c897a6ac22f7f904958,Run 29547923197:TypeScript、SQLite 审计、Schema parity、完整 SQLite 回归、真实 PostgreSQL、生产构建和 migration 资源打包全部通过。一次性 main 验证工作流已删除。

Copy link
Copy Markdown
Owner Author

/validate-pg-access-session

2 similar comments

Copy link
Copy Markdown
Owner Author

/validate-pg-access-session

Copy link
Copy Markdown
Owner Author

/validate-pg-access-session

cropflre and others added 30 commits August 13, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant