Status Update
Comments
da...@google.com <da...@google.com> #2
In the title I was meant to write 1 new column, not 2 new columns.
to...@gmail.com <to...@gmail.com> #3
I noticed something, this is the 2.json schema file that is being generated after the above mentioned changes are completed
{
"tableName": "SubMain",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `subId` TEXT, `sideId` INTEGER, `newColumn` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`), FOREIGN KEY(`subId`) REFERENCES `Main`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`sideId`) REFERENCES `Side`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "subId",
"columnName": "subId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "sideId",
"columnName": "sideId",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "text",
"columnName": "text",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "newColumn", <--- should this be created right now?
"columnName": "newColumn",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_SubMain_subId",
"unique": false,
"columnNames": [
"subId"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_SubMain_subId` ON `${TABLE_NAME}` (`subId`)"
},
{
"name": "index_SubMain_sideId",
"unique": false,
"columnNames": [
"sideId"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_SubMain_sideId` ON `${TABLE_NAME}` (`sideId`)"
}
],
"foreignKeys": [
{
"table": "Main",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"subId"
],
"referencedColumns": [
"id"
]
},
{
"table": "Side",
"onDelete": "NO ACTION",
"onUpdate": "NO ACTION",
"columns": [
"sideId"
],
"referencedColumns": [
"id"
]
}
]
}
as you can see the field entry for the newColumn is already present, but in the previous tests I conducted before, this field would never be added at this stage (?) in order for the migration to be successful.
So I checked the Database_AutoMigration_1_2_Impl
file that is being generated by the auto migration, and I noticed that there is no entry there for adding the new columnn, when I expected to see something like this instead:
database.execSQL("ALTER TABLE 'SubMain' ADD COLUMN 'newColumn' INTEGER NOT NULL DEFAULT 0");
But yet it isn't there.
The only difference I can think of between this failing migration and the previous successful ones I did is this SubMainEntity
is written in a kotlin file, unlike the successful one I did some testing with before, which was written in a .java
file.
This does not seem right? Should the file type of an entity be enough to screw up the auto migration logic?
se...@gmail.com <se...@gmail.com> #4
Curious enough, if I just rename that newColumn
to anything else, the auto migration correctly creates a database SQL entry for that, like this:
database.execSQL("ALTER TABLE 'SubMain' ADD COLUMN 'newColumnRENAMED' INTEGER NOT NULL DEFAULT 0");
Which made me think if maybe the table somehow already had that column from before, so to confirm this I renamed the column to the same original name, cleaned the app, ran the build, and then I completely removed the column from the entity, but the auto migration file did not add any execSQL entry to remove that column. It's like the column is being arbitrarily completely ignored from the auto migration logic.
I tried to check the auto migration builder logic, but I cannot find it, nor do I know how to inspect such a thing since it does not run in the app, but inside the IDE. Why in the world would this specific column be causing this problem?
to...@gmail.com <to...@gmail.com> #5
I think I found the problem, but I cannot check why it is happening because I don't know how to check the automigration logic builder, I can only confirm the result of the bug, but not the origin of it in the source code of the auto migration implementation builder.
Besides the entity I described previously, where I add a newColumn
to it, I also happened to have another entity that also has an exact same column being added to it, same name, and same type, just on a completely different entity.
It seems that when the auto migration builder logic starts reading the changes it is ignoring the newColumn
in SubMainEntity
because it already detected that another entity, let's call it FirstMainEntity
, also has a new column named newColumn
, and so when it generates the auto migration schema this is the result
class Database_AutoMigration_1_2_Impl extends Migration {
public Database_AutoMigration_1_2_Impl() {
super(1, 2);
}
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `FirstMain` ADD COLUMN `newColumn` INTEGER NOT NULL DEFAULT 0");
}
}
However, if I rename the newColumn
in FirstMainEntity
to something different like this:
@ColumnInfo(name = "newColumnTest", defaultValue = "0")
var newColumnTest = false
And run the build, this is what the auto migration generates now:
class Database_AutoMigration_1_2_Impl extends Migration {
public Database_AutoMigration_1_2_Impl() {
super(1, 2);
}
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `SubMain` ADD COLUMN `newColumn` INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE `FirstMain` ADD COLUMN `newColumnTest` INTEGER NOT NULL DEFAULT 0");
}
}
And now the migration runs without an issue.
I can only assume that this is a bug in the auto migration logic, perhaps the new columns are being cached as keys, and being used per database, instead of per table, causing any subsequent table that happens to have a new column with the same @ColumnInfo(name =...
- and I have to emphasize name
here because even when I changed its variable name, or type it made no difference - to not be recognized as having a new column added, except for the first table that was detected.
da...@google.com <da...@google.com> #6
Great detective work! You are totally right in that we have a 'key' bug. Specifically we are incorrectly keeping track of 'added columns without complex changes' using the column name, but forgot to also include the table as part of the key.
See:
I'll fix this soon.
ap...@google.com <ap...@google.com> #7
Branch: androidx-main
commit bfa17ff8b0cff84789e11a7efb384ab08c4f91e6
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Thu Sep 23 12:10:59 2021
Don't key auto-migration added columns by name.
This is not needed and causes issues when two columns of the same name are added to two to dofferent tables.
Bug: 200818663
Test: SchemaDifferTest.kt
Relnote: Fixed an issue with auto-migrations not adding new columns when another table in the same auto-migration also had a new column with the same name.
Change-Id: Ia5db52982e050714f224805d9949215b6caeff56
M room/room-compiler/src/main/kotlin/androidx/room/util/SchemaDiffer.kt
M room/room-compiler/src/main/kotlin/androidx/room/writer/AutoMigrationWriter.kt
M room/room-compiler/src/test/kotlin/androidx/room/util/SchemaDifferTest.kt
M room/room-compiler/src/test/kotlin/androidx/room/writer/AutoMigrationWriterTest.kt
ap...@google.com <ap...@google.com> #8
This is fixed, but sadly didn't make it into 2.4.0-alpha05, it'll be in the next release.
ap...@google.com <ap...@google.com> #9
I have a similar
ap...@google.com <ap...@google.com> #10
sorry I've commented on the wrong issue and it won't let me delete, please ignore!
da...@google.com <da...@google.com> #11
to...@avast.com <to...@avast.com> #12
yb...@google.com <yb...@google.com> #13
mi...@gtempaccount.com <mi...@gtempaccount.com> #14
But I am still seeing this warning:
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
mi...@gtempaccount.com <mi...@gtempaccount.com> #15
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
}
}
}
}
co...@protonmail.com <co...@protonmail.com> #16
yb...@google.com <yb...@google.com> #17
yes, it will be but we are looking for some feedback before we make the switch just to be safe and not break other people.
ap...@google.com <ap...@google.com> #18
Branch: androidx-master-dev
commit 2715143f2b6f2b74a088b242b39c9841d2d8dcf2
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Thu Jun 18 09:54:58 2020
Make room.incremental default be true
Relnote: Room's incremental annotation processing option is now ON by default.
Bug: 112110217
Test: :room:integration-tests:room-i-a-p:test
Change-Id: If46d955da45d985543ab982bd0e9d27bbd961517
M room/compiler/src/main/kotlin/androidx/room/processor/Context.kt
bl...@gmail.com <bl...@gmail.com> #19
Is it switched on by default in 2.2.5? Because I still got the message got a warning from kapt
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
Solved to adding "room.incremental"="true"
in the annotation params.
hu...@google.com <hu...@google.com> #21
KNOWN ISSUE: Note that incremental Room is currently broken in some cases (
hu...@google.com <hu...@google.com> #22
Sorry there was a typo, correction:
Description