whats the best way to migrate a room db to sqldeli...
# squarelibraries
m
whats the best way to migrate a room db to sqldelight. Replicate schema, attach database, and insert select. Would this work?
d
Haven't used it but you should be able to just use the database file as is.
m
ya. but that requires a full migration and is more susceptible to errors than copy paste all data i think. thanks for the suggestion!
o
I just migrated to SqlDelight 2 weeks ago. What do you mean by "copy paste all data"? As Dominic says, the actual database file is the same. Replicate your current schema with SqlDelight and you can access the file as is.
m
yes. But that works for a small application. If you want to gradually migrate you cannot, can you?
You cannot open same database file twice, so you must full migrate
copy paste all data, meaning. You replicate your schema in sqldelight, then attach room db, migrate the tables you want, then close it. And do it by batches
migrate as in ’insert into sqdelight.table1 select * from room.table1 .. etc
d
You can open as many connections to an sqlite database as you want.
But you don't need to do that unless you have pending migrations from users who don't install updates quickly, but that should still be portable.
Just convert you code to sqldelight and use the same filename. No migration need, it should just work.
m
so to be clear, it is possible to use the same db file with room and sqldelight simultaneous, is that what you are saying ?
d
Simultaneously, not completely because notifications won't work as you'd expect, but why would you want to use both simultaneously, just switch.
m
I told you from the beginning. I want to do a partial migration. Because i cannot migrate all at once, it’s too big 😛 It might not be worthwhile, but my question was always about a solution for a partial migration. Not a full on migration
d
migrate as in 'insert into sqdelight.table1 select * from room.table1 .. etc
I thought you meant copy and paste.
Partial migration is tricky because you'll have multiple sources of truth.
m
yes exactly. And to do that, you would have to attach room database. I remember trying something like that, but it failed due to some Room error. Was asking if there is a common approach, thats it
thanks for your help
261 Views