mirror of https://github.com/AMT-Cheif/drift.git
Tests for custom table constraints
This commit is contained in:
parent
becb78afbc
commit
333e71f0a5
|
@ -85,11 +85,7 @@ class Migrator {
|
|||
final constraints = table.asDslTable.customConstraints ?? [];
|
||||
|
||||
for (var i = 0; i < constraints.length; i++) {
|
||||
if (i != 0) {
|
||||
sql.write(', ');
|
||||
}
|
||||
|
||||
sql.write(constraints[i]);
|
||||
sql..write(', ')..write(constraints[i]);
|
||||
}
|
||||
|
||||
sql.write(');');
|
||||
|
|
|
@ -38,6 +38,12 @@ class SharedTodos extends Table {
|
|||
|
||||
@override
|
||||
Set<Column> get primaryKey => {todo, user};
|
||||
|
||||
@override
|
||||
List<String> get customConstraints => [
|
||||
'FOREIGN KEY (todo) REFERENCES todos(id)',
|
||||
'FOREIGN KEY (user) REFERENCES users(id)'
|
||||
];
|
||||
}
|
||||
|
||||
@UseMoor(tables: [TodosTable, Categories, Users, SharedTodos])
|
||||
|
|
|
@ -33,8 +33,13 @@ void main() {
|
|||
'creation_time INTEGER NOT NULL '
|
||||
"DEFAULT (strftime('%s', CURRENT_TIMESTAMP)));"));
|
||||
|
||||
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS shared_todos '
|
||||
'(todo INTEGER NOT NULL, user INTEGER NOT NULL, PRIMARY KEY (todo, user));'));
|
||||
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS shared_todos ('
|
||||
'todo INTEGER NOT NULL, '
|
||||
'user INTEGER NOT NULL, '
|
||||
'PRIMARY KEY (todo, user), '
|
||||
'FOREIGN KEY (todo) REFERENCES todos(id), '
|
||||
'FOREIGN KEY (user) REFERENCES users(id)'
|
||||
');'));
|
||||
});
|
||||
|
||||
test('creates individual tables', () async {
|
||||
|
|
Loading…
Reference in New Issue