objectbox / objectbox/objectbox-java
Default values for new properties
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 4.6k
- Forks
- 311
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Im using ObjectBox in a pet android project written in Kotlin.. I have a data class encoded as such (example):
@Entity data class Foo(var name:String, var description: String) {
constructor() : this("", "") // parameter-less constructor
@Id var id: Long = 0L
// other stuff
}
Database already existed on the device.. I added an additional property to the Foo class (not in the data constructor):
@Entity data class Foo(var name:String, var description: String) {
constructor() : this("", "") // parameter-less constructor
@Id var id: Long = 0L
var bar: String = ""
// other stuff
}
defaulted, non-null object bar.. however when pulling existing records from the stored box, that value bar appears to be null.. I would expect it to be a blank string (default for the parameter); is the violation of not-null guarantee coming from the Java interop?
I fixed the issue by nuking the database; afterwords the entity created and stored is not-null.. But this brings up any possible future updates that may violate this.
Is there a "database upgrade" method for updating already stored objects between versions, adding default values to new properties, or am I resigned to make anything added to an existing model be nullable (and handle it as such)?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue stellt eine Kotlin-Foo-Entität bereit und beschreibt vorhandene Datensätze in einer ObjectBox-Datenbank, nennt jedoch keine Repository-Dateien oder Tests. Beginne damit, das Verhalten nach dem Hinzufügen von bar zu Foo zu reproduzieren, und untersuche anschließend die Pfade für die Entitätsmigration und das Laden vorhandener Datensätze. Als erledigt gilt, wenn geklärt ist, wie neue Nicht-Null-Eigenschaften Standardwerte für gespeicherte Datensätze erhalten, mit Testabdeckung oder Dokumentation für zukünftige Upgrades.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- android, java, kotlin
- Bereich
- databases, mobile-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100