File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,15 @@ class Schema {
13
13
Map <String , dynamic > toJson () => {'tables' : tables};
14
14
15
15
void validate () {
16
+ Set <String > tableNames = {};
16
17
for (var table in tables) {
17
18
table.validate ();
19
+
20
+ if (tableNames.contains (table.name)) {
21
+ throw AssertionError ("Duplicate table name: ${table .name }" );
22
+ }
23
+
24
+ tableNames.add (table.name);
18
25
}
19
26
}
20
27
}
Original file line number Diff line number Diff line change @@ -321,6 +321,41 @@ void main() {
321
321
);
322
322
});
323
323
324
+ test ('Schema without duplicate table names' , () {
325
+ final schema = Schema ([
326
+ Table ('duplicate' , [
327
+ Column .text ('name' ),
328
+ ]),
329
+ Table ('not_duplicate' , [
330
+ Column .text ('name' ),
331
+ ]),
332
+ ]);
333
+
334
+ expect (() => schema.validate (), returnsNormally);
335
+ });
336
+
337
+ test ('Schema with duplicate table names' , () {
338
+ final schema = Schema ([
339
+ Table ('clone' , [
340
+ Column .text ('name' ),
341
+ ]),
342
+ Table ('clone' , [
343
+ Column .text ('name' ),
344
+ ]),
345
+ ]);
346
+
347
+ expect (
348
+ () => schema.validate (),
349
+ throwsA (
350
+ isA <AssertionError >().having (
351
+ (e) => e.message,
352
+ 'message' ,
353
+ 'Duplicate table name: clone' ,
354
+ ),
355
+ ),
356
+ );
357
+ });
358
+
324
359
test ('toJson method' , () {
325
360
final table = Table ('users' , [
326
361
Column ('name' , ColumnType .text),
You can’t perform that action at this time.
0 commit comments