更改 Firebase 数据模型(同时生产多个应用版本) [英] Changing firebase data model (while multiple app versions are in production)

查看:19
本文介绍了更改 Firebase 数据模型(同时生产多个应用版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的 iOS 应用有多个版本在生产中时,更改 Firebase 数据模型的最佳方法是什么?

What's the best way to change the Firebase data model while you have multiple versions of your iOS app in production?

由于中间没有应用程序服务器"层,因此数据库模型中的任何更改都可能破坏旧版本的应用程序.

Since there's no 'application server' layer in the middle any changes in the database model could break older versions of the app.

问题的性能相关示例:

在 1.0 版中,我天真地将与帖子相关的所有内容都保存在/posts/"下.现在在 2.0 版中,我想采纳 Firebase 的建议并添加一个/user-post"端点来快速列出给定用户的所有帖子.

In version 1.0 I was naively keeping everything related to a post under '/posts/'. Now in version 2.0 I want to take Firebase's recommendation and add a '/user-post' endpoint to quickly list all posts for a given user.

使用 1.0 版 iOS 应用程序的人不会将任何数据写入/user-posts",因为该端点过去不存在.因此,使用 2.0 版本的用户看不到使用旧版本应用的用户创建的任何帖子.

People using version 1.0 of the iOS app are not writing any data to '/user-posts' since that endpoint didn't used to exist. People using version 2.0 therefore don't see any posts created by people using the old version of the app.

理论上我可以在某处创建一个服务器来侦听/post/"上的更改并将它们也添加到/user-posts"中.如果您的应用程序有很多不同版本,那么随着时间的推移,这似乎很难维护.

In theory I could create a server somewhere that listens for changes on '/post/' and adds them to '/user-posts' as well. That seems hard to maintain over time though if you have a lot of different versions of your app.

问题的新功能示例:

假设在您的移动应用程序 1.0 版中,您将新博文写到/posts/".现在,在您的应用 2.0 版中,您引入了团队功能,所有帖子都需要在/team/team-id/posts"中.

Lets say in version 1.0 of your mobile app you write new blog posts to '/posts/'. Now in version 2.0 of your app you introduce a Teams feature and all posts need to be in '/team/team-id/posts'.

尚未升级到 2.0 版的人仍将写入/posts".使用 2.0 版的人从/team/team-id/posts"中阅读这些帖子将看不到这些帖子.

People who haven't upgraded to version 2.0 will still be writing to '/posts'. Those posts won't be visible to people using version 2.0 who are reading from '/team/team-id/posts'.

我意识到您可以同时保留两个端点(并根据团队 ID 索引/帖子),但随着时间的推移,这似乎很难维护.

I realize you could keep both endpoints simultaneously (and index /posts based on team ID) but over time this seems hard to maintain.

传统解决方案:

如果我使用 Django 或 Express 之类的东西,我会进行数据库迁移,然后更新服务器端端点以创建博客文章.

If I were using something like Django or Express I'd do a database migration and then update the server-side endpoints for creating blogposts.

这将使客户端的数据库发生更改.理论上,我可以使用 Firebase 在我的架构中添加一个应用程序服务器层,但似乎不推荐这样做:https://firebase.googleblog.com/2013/03/where-does-firebase-fit-in-your-app.html

That would make changes in the database from the clients. I could in theory add an application-server tier to my architecture with Firebase, but that doesn't seem like it's recommended: https://firebase.googleblog.com/2013/03/where-does-firebase-fit-in-your-app.html

推荐答案

如果更新可用.您可以强制用户更新到当前版本,以后不会出现问题,因为无法创建带有旧代码的帖子.

I would suggest you use Firebase Remote Config to show an alert via UIAlertController or different screen if an update is available. You could force the user to update to the current version and you don't have problems later because no posts with the old code can be created.

回答您的问题:我会开发一个不同的应用程序,将它添加到同一个 Firebase 项目,然后让这个应用程序将所有旧数据转换为新数据模型.所以你会在发布新版本后进行一次,旧用户数据转换为新数据模型,一切正常.您还可以为每个对象设置一个类似 databaseVersion 的属性.

To answer your question: I would develop a different app, add it to the same Firebase project and then let this app convert all old data to the new data model. So you would do this one time after releasing the new version and the old user data is converted to the new data model and everything works smoothly. You could also have a property like databaseVersion for every object.

为了防止将来出现问题,您可以在 Firebase 实时数据库 中设置一个名为 app-version 的通用属性.在每次发布之前,应用程序都会检查是否有更新的版本.如果不是,用户可以添加帖子,但如果有更新的版本,您可以通过 UIAlertController

To prevent future problems you could have a general property named app-version in your Firebase Realtime Database. Before every post the app checks if there is a newer version. If not the user can add the post but if there is a newer version you could show an message/alert via UIAlertController

这篇关于更改 Firebase 数据模型(同时生产多个应用版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆