renameColumn method Null safety

void renameColumn(
  1. String tableName,
  2. String columnName,
  3. String newName
)

Validates and renames a column in a table in schema.

Implementation

void renameColumn(String tableName, String columnName, String newName) {
  final table = schema!.tableForName(tableName);
  if (table == null) {
    throw SchemaException("Table $tableName does not exist.");
  }

  final column = table.columnForName(columnName);
  if (column == null) {
    throw SchemaException("Column $columnName does not exists.");
  }

  table.renameColumn(column, newName);

  if (store != null) {
    commands.addAll(store!.renameColumn(table, column, newName));
  } else {
    commands.add(
      "database.renameColumn('$tableName', '$columnName', '$newName');",
    );
  }
}