TableMigration constructor Null safety

TableMigration(
  1. TableInfo<Table, dynamic> affectedTable,
  2. {Map<GeneratedColumn<Object>, Expression<Object>> columnTransformer = const {},
  3. List<GeneratedColumn<Object>> newColumns = const []}
)

Creates migration description on the affectedTable.

Implementation

TableMigration(
  this.affectedTable, {
  this.columnTransformer = const {},
  this.newColumns = const [],
}) {
  // All new columns must either have a transformation or a default value of
  // some kind
  final problematicNewColumns = <String>[];
  for (final column in newColumns) {
    // isRequired returns false if the column has a client default value that
    // would be used for inserts. We can't apply the client default here
    // though, so it doesn't count as a default value.
    final isRequired =
        column.requiredDuringInsert || column.clientDefault != null;
    if (isRequired && !columnTransformer.containsKey(column)) {
      problematicNewColumns.add(column.$name);
    }
  }

  if (problematicNewColumns.isNotEmpty) {
    throw ArgumentError(
      "Some of the newColumns don't have a default value and aren't included "
      'in columnTransformer: ${problematicNewColumns.join(', ')}. \n'
      'To add columns, make sure that they have a default value or write an '
      'expression to use in the columnTransformer map.',
    );
  }
}