DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

@Index

Open brwskitime opened this issue 10 years ago • 4 comments

Has anyone gotten the @Index annotation to work? I've tried it every which way with no luck. It'll compile and creates an IndexProperty in the associated *_Table class, but the sqlite database has no index.

I have gotten @Unique to work though.

brwskitime avatar Mar 09 '16 22:03 brwskitime

So here's my table

@ModelContainer
@Table(database = Database.class, name = TrackLocation.TABLE_NAME,indexGroups = {@IndexGroup(number = 1,name = "trackLocations")})
public class TrackLocation extends BaseTable implements Parcelable {

    public static final String TABLE_NAME = "track_locations";

    @NotNull
    @Index(indexGroups = 1)
    @ForeignKey(
            tableClass = Track.class,
            onDelete = ForeignKeyAction.CASCADE,
            references = {@ForeignKeyReference(
                    columnName = "track_id",
                    foreignKeyColumnName = _ID,
                    referencedFieldIsPackagePrivate = true,
                    columnType = Long.class)})
    protected long track_id;

And the generated _Table class has the index property:


  public static final IndexProperty<TrackLocation> index_trackLocations = new IndexProperty<>("trackLocations", false, TrackLocation.class, track_id);

But no index is actually created. When I pull the database off the device and look at it, there is no index. Seems to me indexing is completely broken.

brwskitime avatar Mar 10 '16 16:03 brwskitime

create an IndexMigration on version 0 that will activate it.

agrosner avatar Mar 10 '16 17:03 agrosner

Thanks for the reply. I hope you'll consider changing this. If I add an the annotations to an existing table class, I would expect to have to do a migration to add the new index. But on a newly created table class with the annotations in place, I'd expect the indexes to get created with the table. Also this appears to be how unique indexing currently works.

brwskitime avatar Mar 10 '16 17:03 brwskitime

https://github.com/Raizlabs/DBFlow/blob/develop/usage2/Indexing.md :)

agrosner avatar Apr 19 '16 03:04 agrosner