Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade my preloaded database for app update #23

Closed
gitton opened this issue Feb 17, 2016 · 8 comments
Closed

upgrade my preloaded database for app update #23

gitton opened this issue Feb 17, 2016 · 8 comments
Labels

Comments

@gitton
Copy link

gitton commented Feb 17, 2016

How can i upgrade my database (pragma user_version 1 to 2 ) with certain changes (like add new table or column) in my database and without changing any user changes made( eg : counter :- number of times an app was used) for my pre built database when updating an app (1.0 to 2.0).

@gitton gitton changed the title upgrade my prebuilt database for app update upgrade my preloaded database for app update Feb 17, 2016
@groue
Copy link
Owner

groue commented Feb 17, 2016

Hello @gitton. I'm not sure I understand the scope of your question. Is it about GRDB, about SQLite, or about the architecture of your application?

@groue groue added the question label Feb 17, 2016
@gitton
Copy link
Author

gitton commented Feb 18, 2016

This is about GRDB. I am new to swift, from android background. In android there is library called android-sqlite-asset-helper (https://github.com/jgilfelt/android-sqlite-asset-helper) in that there is a concept called database upgrade version (https://github.com/jgilfelt/android-sqlite-asset-helper#database-upgrades) i am looking to do similar in GRDB.
Thanks for this library so far this is really cool 👍

@groue
Copy link
Owner

groue commented Feb 18, 2016

There are similar but but not identical concepts in GRDB. The similarities are about running upgrading code when needed, in order to upgrade the database to its latest scheme version. The differences are in the support for database assets: GRDB has none, or more specifically: it lets the resources/documents management to the application developer.

So.

If your application has a bundled database that may be modified by the user or later versions of your application, you need to know the difference between an application resource (immutable), and other mutable files. Check how to copy a database resource into the documents folder, and understand what this sentence means.

Next, versioning. SQLite comes with the user_version pragma, which you can simply query with let version = Int.fetchOne(db, "PRAGMA user_version")!, and set with db.execute("PRAGMA user_version 42").

GRDB also comes with another versioning tool that has my personal preference over user_version, called migrations. Check them out, you may like it.

OK now. I hope this first answer has some food for you!

@groue
Copy link
Owner

groue commented Feb 19, 2016

Hello @gitton. Did you find your way in this maze?

@groue
Copy link
Owner

groue commented Feb 22, 2016

OK. I'm closing this issue since it does not look like it is still relevant to you. Please open a new one if you have another question.

@groue groue closed this as completed Feb 22, 2016
@gitton
Copy link
Author

gitton commented Feb 22, 2016

Sorry for the late response .it Works
Thank you 👍

@groue
Copy link
Owner

groue commented Feb 22, 2016

Great! Happy GRDB!

@danielctf
Copy link

Looks like db.execute("PRAGMA user_version = 42) is working instead of db.execute("PRAGMA user_version 42")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants