Migration with is not idempotent when combining default=null and Maybe type
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
リンク先の行にある Database/Persist/Postgresql.hs 周辺のマイグレーション比較ロジックから始め、次に pull request 1534 の失敗している再現テストを確認してください。Maybe フィールド、nullable の状態、デフォルト値が newcols と既存のカラムでどのように表現されているかを追跡してください。このスキーマに対するマイグレーションを繰り返しても ALTER TABLE ... SET DEFAULT null が出力されなくなり、回帰テストが成功すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
On the project that I work on, we have a default field similar to this:
SomeEntity
name Text Maybe default=null
When we run migrations on the project, we always get:
ALTER TABLE "some_entity" ALTER COLUMN "name" SET DEFAULT null;
The column default gets set as 'nullable' in the database but every time we run migrations this ALTER TABLE is still output.
As with #1532 I looked at this by adding some logging here:
And looked in newcols and fst old' (the new columns vs existing columns), showing the field name and default value on the Column.
Here are the values that were logged out:
-- this is from `newcols`
(FieldNameDB {unFieldNameDB = "text_field"},Just "null")
-- this is from `fst old`
(FieldNameDB {unFieldNameDB = "text_field"},Nothing)
Different to 1532 where there is obviously a mis-match with the cases of the strings, I am less clear what is going on here. I am familiar enough with the types in persistent to know that the concept of nullable is also tracked beyond this field cDefault field here (ie on column there is cNull, there are also similar fields on other types), and I think it might be that in the case where there is Nothing for the default value the null has actually been converted into a flag to signal it being nullable somewhere else (while that hasn't happened on the parsed migration).
I'm not sure at all what the solution would be to this, but I'd be happy to also look to fix this too if I could get some steer in the right direction.
A key point to this issue is I think it is down to the fact that the field is already using Maybe in conjunction to a default null value, in this case, we may not actually need to specify default=null in our entity definitions, and that might be the solution here. But it may also be good for persistent to warn about this if you write this in your entity definitions.
I created a test to recreate this, there is an open PR with failing test here:
- 主要言語
- Haskell
- スター
- 486
- フォーク
- 307
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
yesodweb/persistent のほかの issue
-
use aeson >= 2.3.0.0 to avoid HSEC-2026-0007対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
yesodweb/persistent#1635 · コメント 1 件 · リアクション 1 件 ·
-
Typos in Documentation for Database.Persist.Quasi対応中かも @000wahab000 が 64 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
yesodweb/persistent#1634 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
yesodweb/persistent#1643 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
yesodweb/persistent#1642 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
yesodweb/persistent#1641 ·
yesodweb/persistent の issue をすべて見る
似ている issue
-
agent-ready area:skills
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
jmbarzee/temporal-architect#603 ·
メンテナーはふだん 1 日以内に返信
-
bug dependencies
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
alunduil/network-arbitrary#251 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
`logProbability` returns `NaN` for the Poisson distribution with `λ = 0`対応中かも @youqad が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
haskell/statistics#235 ·
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100