createNoFkUpdateTrigger method
Create a trigger that prevents updates to the primary key.
Implementation
@override
List<String> createNoFkUpdateTrigger(
QualifiedTablename table,
List<String> pk,
) {
final namespace = table.namespace;
final tablename = table.tablename;
return [
'''
CREATE TRIGGER update_ensure_${namespace}_${tablename}_primarykey
BEFORE UPDATE ON $table
BEGIN
SELECT
CASE
${pk.map(
(col) => '''
WHEN old."$col" != new."$col" THEN
\t\tRAISE (ABORT, 'cannot change the value of column $col as it belongs to the primary key')''',
).join('\n')}
END;
END;''',
];
}