objectbox / objectbox/objectbox-java

Default values for new properties

未关闭
#157 32 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
Java
星标
4.6k
派生
311
PR 合并指标
30 天内没有已合并 PR

描述

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)?

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

调研方向

该 issue 提供了一个 Kotlin Foo 实体,并描述了 ObjectBox 数据库中的现有记录,但没有指出任何 repository 文件或测试。首先,在向 Foo 添加 bar 后复现其行为,然后检查实体迁移和现有记录加载路径。完成的标准是确定新的非空属性如何为已存储的记录获取默认值,并为未来的升级提供覆盖或文档。

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

评估

技术栈
android, java, kotlin
领域
databases, mobile-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

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