feat(backend)!: Cloud Database Migration Script - #185
Closed
Alexander-Noah wants to merge 7 commits into
Closed
Alexander-Noah wants to merge 7 commits into
Alexander-Noah wants to merge 7 commits into
Conversation
Replace the existing service, migration, and container scaffolding with the local layered packages and minimal FastAPI entry point. BREAKING CHANGE: the previous timeapp package, health API, Alembic migrations, and backend container setup are removed.
Package the service under src/timeflow, align the versioned API, and add reproducible local and Docker validation. BREAKING CHANGE: backend imports and startup commands now use the timeflow package and timeflow.main:app.
Removed instructions for cloning and starting the project.
Add forward Alembic migrations for accounts, schedules, and occurrence overrides while preserving existing revision history. Reject upgrades when the legacy schedules table contains data. BREAKING CHANGE: the empty legacy schedules table is replaced by the cloud schedule schema during migration.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Alexander-Noah
marked this pull request as ready for review
August 10, 2026 07:44
| """Replace the legacy table only when it contains no data.""" | ||
|
|
||
| connection = op.get_bind() | ||
| legacy_row = connection.execute(sa.text("SELECT 1 FROM schedules LIMIT 1")).first() |
Contributor
There was a problem hiding this comment.
[P1] Lock the legacy table before checking whether it is empty. This SELECT only takes an ACCESS SHARE lock, so another transaction can insert and commit after the check while this migration waits to acquire ACCESS EXCLUSIVE for DROP TABLE. The migration would then silently drop that newly inserted row, defeating the data-loss guard. Acquire an exclusive table lock before the emptiness check (or otherwise quiesce writes), and cover the concurrent-writer case with a regression test.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
Closes #<feat(backend): 建立云端日程 PostgreSQL 三表迁移与 ORM 契约>
变更概述
accounts、schedules、schedule_occurrence_overrides三张业务表。20260810_0003_create_accounts_table.py20260810_0004_create_schedules_table.py20260810_0005_create_schedule_occurrence_overrides_table.py20260728_0001和20260729_0002迁移历史。变更原因
已有的
20260729_0002属于 Alembic 迁移历史,不能直接修改同一个版本号,否则可能导致相同迁移版本对应不同的数据库结构。本 PR 通过新增正向迁移完成三张业务表的结构升级,并在替换旧版
schedules表前检查历史数据:破坏性变更
数据库升级时,空的旧版
schedules表将被替换为新版云端日程表结构。如果旧表中存在数据,迁移会主动失败。旧数据转换不在本 PR 范围内,需要另行设计迁移方案。
验证结果
20260810_0005alembic check检查通过upgrade head升级 → 降级 → 再次升级迁移路径验证通过本次不包含
schedules表的数据转换revision