Hello everyone, I’m sort of new to Kotlin 6-12 Mon...
# squarelibraries
d
Hello everyone, I’m sort of new to Kotlin 6-12 Months working on one Android App which is also my first Kotlin/ Mobile / Mutiplatform Project. In the App I work with SQLDelight to manage my Database and Caching. However with new Versions of the Database no Migrations are being made and the App cannot write to Database / Crashes. Now I did try using .sqm files but it does not seem to find the Database Tables.
I do think I might have to change the build.gradle file. But so far adding any reference to the sqm File resulted in building errors.
b
I think migrations have to be in a specific location, check the doc again on that
d
Is there a specific page mentioning the location? I do not find it on the main Page for Migrations: https://cashapp.github.io/sqldelight/android_sqlite/migrations/
it just mentions the Naming Convetion:
<version to upgrade from>.sqm
which I assume is
1.sqm
if there is no other SQM so far.
s
does the sample app help?
d
I’m assuming you mean the Github Project Sample app? I tried to build it locally but it does not even sync since it uses outdated or missing dependencies. From the gradle build file I also cannot gleam any linking to a Migrations Folder.
s
I found this migration file in the sample app: https://github.com/cashapp/sqldelight/blob/master/sample/common/src/commonMain/sqldelight/migrations/1.sqm. Is this what you were looking for?
d
Yes but the problem is that it does not recognise any of my Tables from the main
.sq
Database file
so there has to be a linking of sorts happening. Which is not documented to my knowledge. In the Sample app I also did not see the Migrations Folder ever being mentioned
s
I was able to build the sample app on my machine. I suspect something else is wrong on your side. Wanna file an issue and share the errors you are seeing?
d
Hello Saket, Regardless of if I get my version of the sample app to run. My question still stands: How do I add a migration file that actually works and applies the Database changes?
b
We put them here
s
@Daniel Bucher I think your migration files are stored in the wrong directory. Wanna share your folder structure?
d
I did change that part yes since I asked my question. However it still does not find the Table.
s
Hmm I'm not sure then. Considering that you're not able to build the sample app either, I think something else is wrong with your environment. Does the migration actually not work at runtime? I can't tell if this is just a false IDE error.
d
True it could be ide error, however I also need to change the Insert Update Query which then does not find the new Column.
Unless that is unrelated and should be added in the .sqm as well
s
can you ignore the IDE errors and check if your SQL queries are running as expected at runtime?
d
Hey thanks for answering. I've been trying to get it to work over here over the last few days. The IDE Error sadly also prevented my project from building. And I haven't so far managed to get my Project to build with an
.sqm
File in it.
s
what happens if you build from a terminal?
d
Hey Saket, Sorry for the delay. I had to sort out some JDK errors and changed a bunch of code for a Store release. But I got this when I build from terminal:
Copy code
.../IdeaProjects/swisscatholicapp/shared/src/commonMain/sqldelight/migrations/1.sqm line 1:12 - No table found with name wpFeaturedMedia
1    ALTER TABLE wpFeaturedMedia ADD COLUMN test TEXT
                 ^^^^^^^^^^^^^^^
Also got this one before that error:
Copy code
line 1:12 - Attempting to alter something that is not a table.
1    ALTER TABLE wpFeaturedMedia ADD COLUMN test TEXT
                 ^^^^^^^^^^^^^^^
also in 1.sqm
the Table is in a statement in the News.sq Database Creation file:
Copy code
CREATE TABLE IF NOT EXISTS wpFeaturedMedia(...);
Without the 1.sqm File I get no errors and the App get's build with the Database. But this won't work if I want to change the Database in a future Play Store update.
s
Ah okay. I'm not sure what's missing then. Can you file an issue on github along with any IDE logs (Help -> Show Log In Finger)?