addIndex method
Implementation
@override
void addIndex(String name, List<String> columns, IndexType type) {
String indexType = '';
switch (type) {
case IndexType.primaryKey:
sql.checkPrimaryKeyColumns(columns);
indexType = 'PRIMARY KEY';
break;
case IndexType.unique:
// A constraint is of columns only, so a unique index of an
// expression, or with an order, is a unique index, as `indexes`
// creates it.
if (!columns.every(sql.isIndexColumnName)) {
_stack.add(_CreateIndex(name, columns, unique: true));
_added.clear();
return;
}
indexType = 'CONSTRAINT ${sql.quotePostgresIdentifier(name)} UNIQUE';
break;
case IndexType.standardIndex:
case IndexType.none:
// Not a clause of ALTER TABLE on PostgreSQL, but a statement of its
// own, after those before it, so that its columns are added.
_stack.add(_CreateIndex(name, columns));
_added.clear();
return;
}
_clause(
'ADD $indexType (${columns.map((c) => sql.compileIndexColumn(c, sql.quotePostgresPart)).join(',')})',
columns,
);
}