-
Notifications
You must be signed in to change notification settings - Fork 376
Description
Is your feature request related to a problem? Please describe.
When using supabase db diff to generate migrations, the diff includes indexes and triggers that were automatically by event triggers (e.g., ON ddl_command_end WHEN TAG IN ('CREATE TABLE')). This means every generated migration for a new table contains redundant statements that fail on apply because the event trigger already created them during CREATE TABLE. We have to manually remove these lines from every generated migration.
I use this as my tables have conventions around having standard columns (e.g. public_id, version, updated_at etc.) and I have scripts that are chained to keep the schemas I manage in supabase/schemas simpler and organized. Also use Prisma as a DSL to use as a base schema (not for its ORM features).
Describe the solution you'd like
An option to exclude specific indexes or triggers from supabase db diff output — for example, a flag like --exclude-pattern or a config file entry that lets users specify object name patterns (regex) to ignore during diff generation (e.g., idx_*_version, handle_standard_columns ...).
Describe alternatives you've considered
- Wrapping the redundant statements in
IF NOT EXISTS/DROP IF EXISTSin the migration output, though this would still produce unnecessary statements (and not current behaviour of themigrationscommand).
Additional context
I use an event trigger (auto_add_standard_infrastructure) that fires on CREATE TABLE to automatically add version indexes and column management triggers to new tables. The event trigger uses CREATE INDEX IF NOT EXISTS so it's safe on its end, but supabase db diff picks up the resulting objects and emits them as plain CREATE INDEX / CREATE TRIGGER statements without IF NOT EXISTS, causing the migration to fail.