I have an offline application and the data is 2-way synchronised between server and the app using pouchdb-couchdb. One requirement is both the server and the app must able to mutate the application data.
Now I have the problem to maintain large application logic on the server side, as there will be multiple version of the app (multiple application logic) running in production, but there's only 1 version of the server.
Example:
Offline Application:
v1.0: increase({ data: 1 }) => ({ data: 1 })
v2.0: increase({ data: { value: 0, percision: 2 }) => ({ data: { value: 1, precision: 2 } })
Server:
# only 1 version allowed, how to maintain?
To resolve this problem, there are 2 possible solutions:
- version my data, and the server will keep track all logic for each version, example
Server:
increase('1.0', { data: 0 }) => ({ data: 1 })
increase('2.0', { data: { value: 0, percision: 2 }) => ({ data: { value: 1, precision: 2 } })
The problem of this approach the server codebase will growth drastically (eg: 100+ function), and we still have two source of truth to maintain.
- store the business logic in the database. In the offline app, we store
increase().prototype.toString()
in db, let it sync with server. Whenever server need the function, it'll just performeval(fn)
. Since only the app will able to mutate the function in the database, we only need to maintain 1 codebase
I personally prefer second approach but I not sure is there any pitfall on this approach. Or is there any better approach to this issue?
v1.0: increase({ data: 0 }) => ({ data: 1 })
, I guess? And notpercision
, butprecision
?