Migration with is not idempotent when combining default=null and Maybe type
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dalla logica di confronto delle migrazioni intorno a Database/Persist/Postgresql.hs alla riga collegata, quindi esamina il test di riproduzione che fallisce in pull request 1534. Traccia come i campi Maybe, lo stato nullable e i valori predefiniti sono rappresentati in newcols e nelle colonne esistenti. Il lavoro è completato quando le migrazioni ripetute non emettono più ALTER TABLE ... SET DEFAULT null per questo schema e il test di regressione passa.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
- Lingua principale
- Haskell
- Stelle
- 486
- Fork
- 307
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di yesodweb/persistent
-
use aeson >= 2.3.0.0 to avoid HSEC-2026-0007Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
yesodweb/persistent#1635 · 1 commento · 1 reazione ·
-
Typos in Documentation for Database.Persist.QuasiForse già presa @000wahab000 l’ha presa 62 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
yesodweb/persistent#1634 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
yesodweb/persistent#1643 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
yesodweb/persistent#1642 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
yesodweb/persistent#1641 ·
Tutte le issue di yesodweb/persistent
Issue simili
-
docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement triage
Difficoltà 1/5 1-3 ore Idoneità per principianti 66/100
simplex-chat/simplex-chat#8043 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
haskell-servant/servant#1929 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
haskell/network-uri#92 ·
-
area:zones rules-correctness
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100