Hash signatures shall be checked on `migrate` call

未关闭
#145 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
postgresql, typescript
领域
databases

调研方向

首先跟踪 migrate 命令以及涉及 graphile_migrate.migrations 表的哈希检查。复现 issue 中描述的 branch-1 和 branch-2 场景,然后验证当现有迁移文件与存储的哈希不同时,migrate 会报告不匹配,同时保留当前匹配时的行为。

由索引模型根据 Issue 内容生成。

描述

Feature description

This is mostly a repeat of what was described in Discord chat, but duplicating here as well for better readability.

Currently, when migrate command is executed, it only checks hashes on the level of database constraint whenever a new migration is applied. But some cases might benefit from comparing existing migration file hashes against hashes stored in database.

Motivating example

Let's say that we have a project with 15 migration files. This state is in branch-1

Now, a refactoring change arrived and we decided to pretty-up existing migration files by combining and re-generating them. We combine some migrations, resulting in 10 different migration files, drop the old database and re-create the database with new migrations. The resulting schema is still the same, we are just using different migration files. Let's say this state is in branch-2.

If we have branch-1 checked out with 15 original migrations applied, switch to branch-2, and run migrate (without running db-reset beforehand) - we get Already up to date message and no errors.
The way I see it, it happens because we have 15 migrations applied, and migrate command cannot find 16-th migration to apply, thinking that all is good.

I would have expected to get an error, stating that there is some sort of mismatch between hashes that are stored in graphile_migrate.migrations table and the files that migrate command uses, but we get no errors.

I could have argued about this, that perhaps this can be checked explicitly by the calling code before migrate command is called, but a reversed case actually does what I would expect.

If we have branch-2 checked out with 10 migrations applied, and switch to branch-1 and try to run migrate command - we get an error insert or update on table "migrations" violates foreign key constraint "migrations_previous_hash_fkey", because migration 11 apply attempt fails because of mismatched hash.

Context of our case: we execute migrate from the code on app startup. During deployment, it was expected for service to fail to start, giving an indication that migrations are wrong... but it started and worked fine 🙂

Supporting development

I [tick all that apply]:

  • am interested in building this feature myself
  • am interested in collaborating on building this feature
  • am willing to help testing this feature before it's released
  • am willing to write a test-driven test suite for this feature (before it exists)
  • am a Graphile sponsor ❤️
  • have an active support or consultancy contract with Graphile
主要语言
TypeScript
星标
836
派生
71
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

graphile/migrate 的其他 Issue

查看 graphile/migrate 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。