swiftydb icon indicating copy to clipboard operation
swiftydb copied to clipboard

Adding new field to class during project

Open adipso-jerome opened this issue 8 years ago • 11 comments

Hello, When adding a new field to my class, it seams to not be create into database. If i try to make a print of that new field, it display error "fatal error: unexpectedly found nil while unwrapping an Optional value"

adipso-jerome avatar Mar 24 '16 08:03 adipso-jerome

At the moment, migration isn't automated. I have been a little busy the last few months.

I have a few days off now, so I can probably fix it before Saturday, if that would suffice?

Oyvindkg avatar Mar 24 '16 10:03 Oyvindkg

It's perfect thanks :)

adipso-jerome avatar Mar 24 '16 10:03 adipso-jerome

I am spending my Easter deep in the Norwegian mountains, and I seem to have lost my internet connection (writing this on my phone). I'm afraid it will be a little delayed.

As SQLite's ALTER TABLE only supports adding columns and renaming tables, I'm not sure how I want to implement it at the moment.

If you need it asap, or you want to contribute, you are welcome to give it a try and send a pull request! :)

Oyvindkg avatar Mar 25 '16 09:03 Oyvindkg

ok for the delay, i will wait a little. Here I find Alter table in sqlite : http://stackoverflow.com/questions/4253804/insert-new-column-into-table-in-sqlite Sorry, I can't help you, I have already my own project to go ahead :)

adipso-jerome avatar Mar 25 '16 16:03 adipso-jerome

If automatic migration is added, I think it should at least support adding and removing columns. This isn't possible using SQLites alter table.

I understand. Best of luck with your project :)

Oyvindkg avatar Mar 25 '16 23:03 Oyvindkg

Its true, removing is not support by sqlite. Since its a sqlite problem, people will understand that the field they just delete from class won't be delete from table (even if they don't use swiftydb, the problem will be the same).

adipso-jerome avatar Mar 26 '16 00:03 adipso-jerome

FYI: you can perform any alteration you want to an SQLite table, including removing columns: https://www.sqlite.org/lang_altertable.html#otheralter

groue avatar Apr 01 '16 20:04 groue

Yes, that would be the naïve, and probably the best approach. As I didn't have a chance to work on this during the Easter due to connection problems, and I am quite busy until May. I'll push a new version as soon as possible

Oyvindkg avatar Apr 02 '16 00:04 Oyvindkg

The implementation is mostly done, but it needs to be tested

Oyvindkg avatar Apr 02 '16 23:04 Oyvindkg

https://www.techonthenet.com/sqlite/tables/alter_table.php

this will help you

izouxv avatar Feb 16 '17 09:02 izouxv

Thank you @izouxv.

2.0 will apply the described process to automatically reflect updated types.

Oyvindkg avatar Apr 27 '17 21:04 Oyvindkg