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 {
1313 Map <String , dynamic > toJson () => {'tables' : tables};
1414
1515 void validate () {
16+ Set <String > tableNames = {};
1617 for (var table in tables) {
1718 table.validate ();
19+
20+ if (tableNames.contains (table.name)) {
21+ throw AssertionError ("Duplicate table name: ${table .name }" );
22+ }
23+
24+ tableNames.add (table.name);
1825 }
1926 }
2027}
Original file line number Diff line number Diff line change @@ -321,6 +321,41 @@ void main() {
321321 );
322322 });
323323
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+
324359 test ('toJson method' , () {
325360 final table = Table ('users' , [
326361 Column ('name' , ColumnType .text),
You can’t perform that action at this time.
0 commit comments