renderAlterAddColumns method
List<String>
renderAlterAddColumns(
- String table,
- TableBlueprint changes, {
- String afterColumn = '',
- String beforeColumn = '',
override
Implementation
@override
List<String> renderAlterAddColumns(
String table,
TableBlueprint changes, {
String afterColumn = '',
String beforeColumn = '',
}) {
// SQLite's ALTER TABLE cannot add these after the fact, and quietly
// dropping them would leave the schema silently missing a constraint.
final unsupported = <String>[
if (changes.primaryKey != null) 'a primary key',
if (changes.uniqueConstraints.isNotEmpty) 'unique constraints',
if (changes.foreignKeys.isNotEmpty) 'foreign keys',
];
if (unsupported.isNotEmpty) {
throw UnsupportedError(
'SQLite cannot add ${unsupported.join(', ')} to the existing table '
'"$table". Recreate the table with the constraint instead.',
);
}
final statements = <String>[];
for (final col in changes.columns) {
statements.add(
'ALTER TABLE "$table" ADD COLUMN ${_renderColumn(col, false)}',
);
}
for (final idx in changes.indexes) {
statements.addAll(renderAddIndex(table, idx));
}
return statements;
}