Add ability to pass persistent store options as parameter #12

Closed
opened 2025-12-29 15:22:01 +01:00 by adam · 1 comment
Owner

Originally created by @sidlatau on GitHub (Sep 28, 2015).

I was unable to enable automatic migrations without modifying CoreStore code (to enable NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption flags).

I added additional parameter to addSQLiteStoreAndWait method for passing options.

    try dataStack.addSQLiteStoreAndWait(
        fileURL: sqliteFileURL, // set the target file URL for the sqlite file
        storeOptions: [NSSQLitePragmasOption: ["journal_mode": "WAL"], NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
    )

Is there a better way to enable automatic migrations without this modification?

Originally created by @sidlatau on GitHub (Sep 28, 2015). I was unable to enable automatic migrations without modifying CoreStore code (to enable NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption flags). I added additional parameter to addSQLiteStoreAndWait method for passing options. ``` try dataStack.addSQLiteStoreAndWait( fileURL: sqliteFileURL, // set the target file URL for the sqlite file storeOptions: [NSSQLitePragmasOption: ["journal_mode": "WAL"], NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true] ) ``` Is there a better way to enable automatic migrations without this modification?
adam added the question label 2025-12-29 15:22:01 +01:00
adam closed this issue 2025-12-29 15:22:02 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Sep 28, 2015):

@sidlatau Thanks for the feedback!
The DataStack already sets ["journal_mode": "WAL"] for you! If you search the code for "journal_mode": "WAL" you'll see that it's being set inside addSQLiteStoreAndWait(...).

As for NSMigratePersistentStoresAutomaticallyOption, and NSInferMappingModelAutomaticallyOption, CoreStore is smart enough to do the same migration introspection without setting these flags. But, CoreStore does not allow migrations when you use addSQLiteStoreAndWait(...) because this is a blocking method and migrations may take time. To support migrations, you have to use the asynchronous methods of the form addSQLiteStore(... completion:) instead.

It will help you a lot if you read the README on migrations for more details. Feel free to ask any other questions!

@JohnEstropia commented on GitHub (Sep 28, 2015): @sidlatau Thanks for the feedback! The `DataStack` already sets `["journal_mode": "WAL"]` for you! If you search the code for **"journal_mode": "WAL"** you'll see that it's being set inside `addSQLiteStoreAndWait(...)`. As for `NSMigratePersistentStoresAutomaticallyOption`, and `NSInferMappingModelAutomaticallyOption`, CoreStore is smart enough to do the same migration introspection without setting these flags. But, CoreStore does not allow migrations when you use `addSQLiteStoreAndWait(...)` because this is a blocking method and migrations may take time. To support migrations, you have to use the asynchronous methods of the form `addSQLiteStore(... completion:)` instead. It will help you a lot if you read the README on [migrations](https://github.com/JohnEstropia/CoreStore#migrations) for more details. Feel free to ask any other questions!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#12