https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
d

Daniel Bucher

06/24/2022, 10:37 AM
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

Benoit Quenaudon

06/24/2022, 11:44 AM
I think migrations have to be in a specific location, check the doc again on that
d

Daniel Bucher

06/24/2022, 11:48 AM
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

saket

06/24/2022, 12:49 PM
does the sample app help?
d

Daniel Bucher

06/24/2022, 1:12 PM
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

saket

06/24/2022, 1:17 PM
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

Daniel Bucher

06/24/2022, 1:18 PM
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

saket

06/24/2022, 2:17 PM
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

Daniel Bucher

06/24/2022, 3:12 PM
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

Benoit Quenaudon

06/24/2022, 3:58 PM
We put them here
s

saket

06/24/2022, 4:00 PM
@Daniel Bucher I think your migration files are stored in the wrong directory. Wanna share your folder structure?
d

Daniel Bucher

06/24/2022, 4:13 PM
I did change that part yes since I asked my question. However it still does not find the Table.
s

saket

06/24/2022, 4:16 PM
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

Daniel Bucher

06/24/2022, 4:18 PM
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

saket

06/24/2022, 4:26 PM
can you ignore the IDE errors and check if your SQL queries are running as expected at runtime?
d

Daniel Bucher

06/28/2022, 3:56 PM
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

saket

06/28/2022, 3:57 PM
what happens if you build from a terminal?
d

Daniel Bucher

06/29/2022, 12:46 PM
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

saket

06/29/2022, 3:49 PM
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)?
22 Views