mirror of https://github.com/AMT-Cheif/drift.git
Fix attached index not resolving
This commit is contained in:
parent
09d450e7f5
commit
27b459d3c6
|
@ -691,10 +691,17 @@ abstract class _$Database extends GeneratedDatabase {
|
|||
$TodoCategoryItemCountView(this);
|
||||
late final $TodoItemWithCategoryNameViewView customViewName =
|
||||
$TodoItemWithCategoryNameViewView(this);
|
||||
late final Index itemTitle =
|
||||
Index('item_title', 'CREATE INDEX item_title ON todo_items (title)');
|
||||
@override
|
||||
Iterable<TableInfo<Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
|
||||
@override
|
||||
List<DatabaseSchemaEntity> get allSchemaEntities =>
|
||||
[todoCategories, todoItems, todoCategoryItemCount, customViewName];
|
||||
List<DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
todoCategories,
|
||||
todoItems,
|
||||
todoCategoryItemCount,
|
||||
customViewName,
|
||||
itemTitle
|
||||
];
|
||||
}
|
||||
|
|
|
@ -230,7 +230,9 @@ class DriftAnalysisDriver {
|
|||
assert(state.discovery != null || state.cachedDiscovery != null);
|
||||
assert(id.libraryUri == state.ownUri);
|
||||
|
||||
if (!state.elementIsAnalyzed(id)) {
|
||||
if (state.elementIsAnalyzed(id)) {
|
||||
return state.analysis[id]?.result;
|
||||
} else {
|
||||
final resolver = DriftResolver(this);
|
||||
|
||||
try {
|
||||
|
@ -241,10 +243,10 @@ class DriftAnalysisDriver {
|
|||
|
||||
if (_isTesting) rethrow;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Resolves elements in a file under the given [uri] by doing all the
|
||||
|
|
|
@ -66,6 +66,34 @@ class Tags extends Table {
|
|||
}, result.dartOutputs, result.writer);
|
||||
});
|
||||
|
||||
test('generates index attached to table in same file', () async {
|
||||
// Regression test for https://github.com/simolus3/drift/discussions/2766
|
||||
final result = await emulateDriftBuild(
|
||||
inputs: {
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
@TableIndex(name: 'tag_id', columns: {#id})
|
||||
class Tags extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
}
|
||||
|
||||
@DriftDatabase(tables: [Tags])
|
||||
class MyDatabase {}
|
||||
''',
|
||||
},
|
||||
);
|
||||
|
||||
checkOutputs({
|
||||
'a|lib/a.drift.dart': decodedMatches(allOf(
|
||||
contains(
|
||||
"Index tagId = Index('tag_id', 'CREATE INDEX tag_id ON tags (id)')",
|
||||
),
|
||||
contains('allSchemaEntities => [tags, tagId]'),
|
||||
)),
|
||||
}, result.dartOutputs, result.writer);
|
||||
});
|
||||
|
||||
test('generates index attached to table in modular build', () async {
|
||||
final result = await emulateDriftBuild(
|
||||
inputs: {
|
||||
|
|
Loading…
Reference in New Issue