Tests for custom table constraints

This commit is contained in:
Simon Binder 2019-04-19 20:38:58 +02:00
parent becb78afbc
commit 333e71f0a5
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
3 changed files with 14 additions and 7 deletions

View File

@ -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(');');

View File

@ -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])

View File

@ -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 {