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

Database upgrade/versioning support #10

Closed
satyan opened this issue Nov 21, 2012 · 8 comments
Closed

Database upgrade/versioning support #10

satyan opened this issue Nov 21, 2012 · 8 comments

Comments

@satyan
Copy link
Collaborator

satyan commented Nov 21, 2012

Need database upgrade/versioning support.

  • feature requested in community
@satyan
Copy link
Collaborator Author

satyan commented Nov 21, 2012

We've added support for that recently. This feature is still in beta stage.

Here's how you'd do it.

  1. Create a folder named "sugar_upgrades" in your assets folder.
  2. Create a file named <db_version>.sql in that folder. eg. 1.sql, 2.sql
  3. This file would contain all the update/alter queries for that particular version.
  4. Change the version field in AndroidManifest.xml
<meta-data android:name="VERSION" android:value="2" />
  1. This would execute all the .sql files that have changed from your current version.

@tobykurien
Copy link

That sounds great! Like Rails migrations. I like it.

@tsuharesu
Copy link

What if I already have a DB? What Sugar will do the first time the app open (after the upgrade)?

Will it have some Exceptions because the tables already exists, will it drop all the tables?

And if I have scripts, will it just use the scripts or will it try to create the tables?

Just some questions =P

@satyan
Copy link
Collaborator Author

satyan commented Aug 12, 2013

@tsuharesu An upgrade right now just executes the migration scripts.
http://satyan.github.io/sugar/migration.html

@tsuharesu
Copy link

Hmm, understood. If I have the scripts, they will be executed. If not, dropTable > createTable.
https://github.com/satyan/sugar/blob/master/library/src/com/orm/SugarDb.java#L137

Thanks 👍

@whoshuu whoshuu closed this as completed Jul 8, 2014
@rastoarpit
Copy link

After upgrading my sugar[using 1.3] record, with alter table query i am adding a column to existing table.
Column is there but when i add a value and save it then it does not work rather it takes a null/default value even after the upgrade. While everything works great on fresh install where table gets created with this column already.

@refaelsh
Copy link

I have exactly the same problem as rastoarpit.

@8manuel
Copy link

8manuel commented Mar 15, 2017

I have the same problem as @rastoarpit and @refaelsh
Even in the log it appears the alter table
I/Sugar: ALTER TABLE ROSCA ADD COLUMN PHOTO TEXT
However debugging the new column not appears

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

No branches or pull requests

7 participants