Closed brwskitime closed 8 years ago
I don't think index creation works automatically. At least in my experience I've had to run a migration to get it to work. There's a thread at https://github.com/Raizlabs/DBFlow/issues/160 regarding doing this on initial db creation:
it will do a CREATE IF NOT EXISTS
statement if you execute it. Also there's an IndexMigration
which you can use to auto-add Index
to DB for versions. But I think this can be better via the generated IndexProperty
. I will look into making a simple one for that.
just create a subclass of BaseMigration
like so:
public class IndexPropertyMigration extends BaseMigration {
private final IndexProperty indexProperty;
public IndexPropertyMigration(IndexProperty indexProperty) {
this.indexProperty = indexProperty;
}
@Override
public void migrate(DatabaseWrapper database) {
indexProperty.createIfNotExists(database);
}
}
and subclass it with proper annotation:
@Migration(version = MyDatabase.VERSION, database = MyDatabase.class)
public class MyIndexPropertyMigration extends IndexPropertyMigration {
private final IndexProperty indexProperty;
public IndexPropertyMigration() {
super(MyTable_Table.index_myIndexProperty);
}
}
Why do you need a migration on a new table?? It should be part of the table creation. It's also not consistent with unique index creation. Also tried this and it only runs the migration on a database upgrade. So new users/fresh install will still not get my index. This is broken IMO.
Any updates on this? Why shall this not be fixed for fresh installs?
I'm completely agree with @brwskitime :+1: Any updates on this?
I've followed the instructions. Here's the relevant part of my table showing what I want to index:
And then a query to get rows ordered by the index:
Pretty straight forward and it all compiles. However pulling the database from my emulator shows that no index was created and of course I get an exception as soon as I run the query.
If I yank the .indexedBy() call, It'll run but there still is no index. Yes I've tried making the index name something other than the column name. What am I missing?