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

查看:112
本文介绍了更改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.

使用iOS应用程序1.0版的用户不会将任何数据写入"/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'.从'/team/team-id/posts'中读取的使用2.0版的人将看不到这些帖子.

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将应用程序服务器层添加到我的体系结构中,但是似乎不建议这样做:

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

推荐答案

我建议您使用Firebase Remote Config通过UIAlertController或其他屏幕(如果有可用更新)显示警报.您可以强迫用户更新到当前版本,以后再也不会出现问题,因为无法创建带有旧代码的帖子.

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 Realtime Database中具有一个名为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天全站免登陆