Re: CoreData database sharing and migration
Re: CoreData database sharing and migration
- Subject: Re: CoreData database sharing and migration
- From: Tobias Jordan <email@hidden>
- Date: Sat, 20 Mar 2010 14:16:06 +0100
Hi Ben,
Does this mean I can't use any mapping models anymore since they only
update from one data model to another one? What's the right class to
do it manually?
Thanks.
- Tobias
On Mar 17, 2010, at 11:35 PM, Ben Trumbull wrote:
About the second question -- do you know how to solve the migration
with more than two data models?
From a specific NSPersistentStore's perspective there is only ever 1
data model. When you use multiple models and merge them together,
then *union* is "the" data model. The object you pass to the
NSPersistentStoreCoordinator initializer is the one true data model
regardless of whether it only exists in memory or how many separate
model files were used to compose it.
When you migrate a store that is built on the union of multiple
models, you must migrate the union to a new union. You cannot
migrate things piecemeal. However, as you can merge models together
at runtime, so too could you construct mapping models
programmatically to handle the union. However, that's probably
more trouble than it's worth. You should focus on migrating the
union model that was used with the store as its own entity.
It might be easier to think about how you would give each schema a
version number. Each union of models is likely to be its own
version, and you would migrate to a new union with a new version
number.
- Ben
On Mar 17, 2010, at 3:28 PM, Tobias Jordan wrote:
Hi Ben,
Thanks so much for this brilliant suggestion, I haven't thought
about something like this before but it's actually really fantastic.
About the second question -- do you know how to solve the migration
with more than two data models?
- Tobias
On Mar 17, 2010, at 11:13 PM, Ben Trumbull wrote:
On Mar 17, 2010, at 2:59 PM, Tobias Jordan wrote:
Hello Ben,
Thanks a lot for responding! My problem is as follows: The
database which is currently a non-document based core data SQLite
one is normally stored in the local User Library of the user. (/
Users/user/Library/Application Support/MyApp/database.db
But there are cases in which two (or more) different physical
machines must have access to the database.
Don't do that. Network file systems do not provide real time
distributed cache coherency. NFS is not a free version of Oracle.
For example two designers working on a project and they both need
the same database so they can share their results. This means
they create a new database on their server and link my app to
this database.
Each machine can have its own database and they can share their
results with NSDistributedNotification or some other IPC/
networking protocol. You can hook into the
NSManagedObjectContextDidSaveNotification to track when one of the
peers has committed changes locally.
- Ben
As you've said, is there a way the data can be always immediately
written to disk so there's no 'last writer wins'?
I am not using NSDocument based techniques -- it is really just
one core data DB.
Thank you!
Regards,
Tobias
On Mar 17, 2010, at 10:29 PM, Ben Trumbull wrote:
I am wondering whether it is possible to create a database in
core
data that can be opened by more than one application at the
same time.
It is currently impossible to handle one SQLite database with two
instances of the same app. The problem is if user1 quits the
app, the
data is saved but user2's instance of the app doesn't recognize
this
file system change and just overwrites its version in memory.
So the
data from user1 is gone. Is there a way I can handle this?
Second -- I am having more than two database versions now but
still
want to support my version 1.0 but the mapping model only
allows one
source model as well as only one target model. I would have to
remove
one version but that makes version 1.0 users' database unusable.
Has anyone gotten something like this to work?
Yes, several Apple frameworks use Core Data databases from
multiple processes simultaneously with a single user account and
single physical machine.
Do you mean "more than one application simultaneously on more
than one physical computer over NFS/AFP/SMB" ? Don't do that.
Or do you mean an NSDocument based application using Core Data &
an SQLite store ? NSDocuments intentionally behave like
TextEdit. Last writer wins, overwites everything. If so, you
should be using a non-document based Core Data project template.
- Ben
- Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden