like method

List<ComparisonWarning<ComparisonWarning>> like(
  1. TableDefinition other
)

Compares this table definition with other, returning a list of mismatches.

Implementation

List<ComparisonWarning> like(TableDefinition other) {
  List<ComparisonWarning> mismatches = [];

  if (other.name != name) {
    mismatches.add(
      TableComparisonWarning(
        name: 'name',
        expected: name,
        found: other.name,
      ),
    );
  }

  if (other.tableSpace != tableSpace) {
    mismatches.add(
      TableComparisonWarning(
        name: 'tablespace',
        expected: tableSpace,
        found: other.tableSpace,
      ),
    );
  }

  if (managed != null && other.managed != null && managed != other.managed) {
    mismatches.add(
      TableComparisonWarning(
        name: 'managed property',
        expected: '$managed',
        found: '${other.managed}',
      ),
    );
  }

  for (var column in columns) {
    var otherColumn = other.findColumnNamed(column.name);
    if (otherColumn == null) {
      mismatches.add(
        ColumnComparisonWarning(
          name: column.name,
          expected: column.name,
          found: null,
        ),
      );
    } else {
      var columnMismatches = column.like(otherColumn);
      if (columnMismatches.isNotEmpty) {
        mismatches.add(
          ColumnComparisonWarning(
            name: column.name,
          ).addSubs(columnMismatches),
        );
      }
    }
  }

  for (var index in indexes) {
    var otherIndex = other.findIndexNamed(index.indexName, ignoreCase: true);
    if (otherIndex == null) {
      mismatches.add(
        IndexComparisonWarning(
          name: index.indexName,
          expected: index.indexName,
          found: null,
        ),
      );
    } else {
      var indexMismatches = index.like(otherIndex, ignoreCase: true);
      if (indexMismatches.isNotEmpty) {
        mismatches.add(
          IndexComparisonWarning(
            name: index.indexName,
          ).addSubs(indexMismatches),
        );
      }
    }
  }

  for (var foreignKey in foreignKeys) {
    var otherForeignKey = other.findForeignKeyDefinitionNamed(
      foreignKey.constraintName,
      ignoreCase: true,
    );
    if (otherForeignKey == null) {
      mismatches.add(
        ForeignKeyComparisonWarning(
          name: foreignKey.constraintName,
          expected: foreignKey.constraintName,
          found: null,
        ),
      );
    } else {
      var foreignKeyMismatches = foreignKey.like(
        otherForeignKey,
        ignoreCase: true,
      );
      if (foreignKeyMismatches.isNotEmpty) {
        mismatches.add(
          ForeignKeyComparisonWarning(
            name: foreignKey.constraintName,
          ).addSubs(foreignKeyMismatches),
        );
      }
    }
  }

  return mismatches;
}