pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
967 stars 191 forks source link

Creating new tables within an existing DB #775

Open kevin-haynie opened 1 year ago

kevin-haynie commented 1 year ago

What is the best way to add a table to an existing database? Right now, if I add a new entity, model, DAO that's fine but Floor will never create my new table.

I can call your onCreate method directly and it almost works except for the fact that you create CREATE INDEX statements which unfortunately do not include IF NOT EXISTS. The IF NOT EXISTS clause is included for everything else including tables and views.

To me, it seems that Floor should automatically attempt to ensure that all entities are created in the DB. We shouldn't have to write a migration routine just to create a brand new table.

Thoughts?

dkaera commented 1 year ago

@kevin-haynie Yes, it makes sense to add IF NOT EXISTS for indexes, maybe as option. But I'm not sure I fully understand why the table is not created without it....

kevin-haynie commented 1 year ago

You're right, the table will be created without it but when any of the create index statements is attempted for pre-existing tables, it fails and throws an exception. I would like to avoid this exception since it's not really an error when we try to create an index when it already exists.

shawoozy commented 1 year ago

@kevin-haynie how did you manage to call tje onCreate directly ?