SchemaColumnDifference constructor Null safety

SchemaColumnDifference(
  1. SchemaColumn? expectedColumn,
  2. SchemaColumn? actualColumn
)

Creates a new instance that represents the difference between expectedColumn and actualColumn.

Implementation

SchemaColumnDifference(this.expectedColumn, this.actualColumn) {
  if (actualColumn != null && expectedColumn != null) {
    if (actualColumn!.isPrimaryKey != expectedColumn!.isPrimaryKey) {
      throw SchemaException(
        "Cannot change primary key of '${expectedColumn!.table!.name}'",
      );
    }

    if (actualColumn!.relatedColumnName !=
        expectedColumn!.relatedColumnName) {
      throw SchemaException(
        "Cannot change an existing column '${expectedColumn!.table!.name}.${expectedColumn!.name}' to an inverse Relationship",
      );
    }

    if (actualColumn!.relatedTableName != expectedColumn!.relatedTableName) {
      throw SchemaException(
        "Cannot change type of '${expectedColumn!.table!.name}.${expectedColumn!.name}'",
      );
    }

    if (actualColumn!.type != expectedColumn!.type) {
      throw SchemaException(
        "Cannot change type of '${expectedColumn!.table!.name}.${expectedColumn!.name}'",
      );
    }

    if (actualColumn!.autoincrement != expectedColumn!.autoincrement) {
      throw SchemaException(
        "Cannot change autoincrement behavior of '${expectedColumn!.table!.name}.${expectedColumn!.name}'",
      );
    }

    if (expectedColumn!.name.toLowerCase() !=
        actualColumn!.name.toLowerCase()) {
      _differingProperties.add(
        _PropertyDifference(
          "name",
          expectedColumn!.name,
          actualColumn!.name,
        ),
      );
    }

    if (expectedColumn!.isIndexed != actualColumn!.isIndexed) {
      _differingProperties.add(
        _PropertyDifference(
          "isIndexed",
          expectedColumn!.isIndexed,
          actualColumn!.isIndexed,
        ),
      );
    }

    if (expectedColumn!.isUnique != actualColumn!.isUnique) {
      _differingProperties.add(
        _PropertyDifference(
          "isUnique",
          expectedColumn!.isUnique,
          actualColumn!.isUnique,
        ),
      );
    }

    if (expectedColumn!.isNullable != actualColumn!.isNullable) {
      _differingProperties.add(
        _PropertyDifference(
          "isNullable",
          expectedColumn!.isNullable,
          actualColumn!.isNullable,
        ),
      );
    }

    if (expectedColumn!.defaultValue != actualColumn!.defaultValue) {
      _differingProperties.add(
        _PropertyDifference(
          "defaultValue",
          expectedColumn!.defaultValue,
          actualColumn!.defaultValue,
        ),
      );
    }

    if (expectedColumn!.deleteRule != actualColumn!.deleteRule) {
      _differingProperties.add(
        _PropertyDifference(
          "deleteRule",
          expectedColumn!.deleteRule,
          actualColumn!.deleteRule,
        ),
      );
    }
  }
}