mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
How to destroy a SQLiteStore? #273
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dginsburg on GitHub (May 22, 2019).
Hi John,
I'm working on a new project and want to thank you for CoreStore. I was dreading using Core Data after my past experiences but CoreStore really improves the situation.
I'm struggling with how to safely delete a SQLiteStore that has already been added to the stack. This is what I've implemented but I'm not confident in it at all. This seems like a capability that would be better as a part of CoreStore so it can clean up first.
I'm holding onto a reference for the
DataStackso I can do what it does asynchronously indeinit. For reasons I don't understand,destroyPersistentStoredoesn't delete the files so I delete them manually.With some basic testing I've already seen CoreStore throw exceptions due to underlying file access issues for in flight transactions. CoreStore handles the exceptions gracefully, but that doesn't seem like a proper solution. It also smells that I have to use something called
unsafeContextto accomplish this.I think what I'm doing is not an uncommon use case. Our customers can be in multiple accounts and I'd like to isolate the accounts and just delete the entire store if they lose access to one of them.
Ideas? Thanks.
@Lapinou42 commented on GitHub (Sep 10, 2019):
Hello,
Did you find a solution ? I'm exactly in the same case as you.
Thank you !
@JohnEstropia commented on GitHub (Sep 22, 2019):
I would suggest to let the
DataStackdeallocate itself first, then delete the related files. Admittedly this is very difficult the way CoreStore is currently designed (which is why I haven't written public utilities for it). I do have projects that regularly recreates stores, you just have to manage the DataStack lifecyle on your own.How I do it: