https://kotlinlang.org logo
j

jean

03/26/2021, 6:59 AM
I’m using sqldelight in my multiplateform package. I want to add a new table to my existing database. Should I create a migration file 
1.sqm
  and have the
CREATE
statement there? What about the requests I want to make on that table, should they be in the same migration file?
k

KamilH

03/26/2021, 7:05 AM
You should have
CREATE TABLE
in your
.sq
file (for new users) and put there all of the “requests” to this table. At the same time you should create
1.sqm
file that contains only
CREATE TABLE
statement (for current users) that is exactly the same as in
.sq
file
You can easily test it by overwriting old version of the app with the new one that have only new
.sq
file. It should crash at the startup. Then you can add
1.sqm
file and try it again and see if it fixed a problem 🙂
j

jean

03/26/2021, 8:16 AM
I did this with small twist, I had to use
IF NOT EXISTS
in the
sqm
file otherwise the IDE complains the table already exists. Thanks 🙂
k

KamilH

03/26/2021, 8:20 AM
Interesting, I’ve never had to do it. Thanks for the info 🙂
2 Views