Oyvindkg / swiftydb

💀Neither supported nor maintained for years. A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding new field to class during project

adipso-jerome opened this issue · 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"

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?

It's perfect thanks :)

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! :)

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 :)

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 :)

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).

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

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

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

Thank you @izouxv.

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