db diff -f ignores schema_paths order in config.toml
Description
The db diff -f generated_migration command does not respect the order defined in config.toml under [db.migrations] schema_paths. Instead of following the specified order, all definitions in the generated migration file are sorted lexicographically by table/definition name, which can cause dependency issues during migration execution.
Steps to Reproduce
- Create a nested schema structure in
./schemas/
- Define tables and functions in different directories:
./schemas/dir_name_1/function1.sql
./schemas/dir_name_2/table1.sql
- Configure the desired order in
config.toml:
[db.migrations]
schema_paths = [
"./schemas/dir_name_1/function1.sql",
"./schemas/dir_name_2/table1.sql"
]
- Run
db diff -f test
- Examine the generated migration file
- Attempt to run
supabase db reset
Expected Behavior
- Migration file
TIMESTAMP_generated_migration.sql should be generated
- Definitions should be ordered according to the
schema_paths configuration
supabase db reset should execute successfully without dependency errors
Actual Behavior
- Generated migration file sorts definitions lexicographically, ignoring
schema_paths order
supabase db reset fails when table names come before function names alphabetically, as functions are defined after tables in the migration file despite the configuration
Screenshots
Schema Structure
Configuration
Generated Migration (showing incorrect order)
Environment Information
- Ticket ID:
9ab2a8e41ff24f22b98a4746f4417224
- OS: macOS Sequoia 15.5 (24F74)
- CLI Version: 2.30.4
- Docker Version: 28.2.2 (build e6534b4)
Service Versions
- supabase/postgres:
15.8.1.030
- supabase/gotrue:
v2.176.1
- postgrest/postgrest:
v12.2.3
- supabase/realtime:
v2.38.0
- supabase/storage-api:
v1.24.7
- supabase/edge-runtime:
v1.67.4
- supabase/studio:
2025.06.30-sha-6f5982d
- supabase/postgres-meta:
v0.89.3
- supabase/logflare:
1.14.2
- supabase/supavisor:
2.5.6
Impact
This issue prevents proper dependency management in database schemas, leading to failed migrations when objects depend on a specific creation order (e.g., functions that must be created before tables that reference them).
db diff -fignoresschema_pathsorder inconfig.tomlDescription
The
db diff -f generated_migrationcommand does not respect the order defined inconfig.tomlunder[db.migrations] schema_paths. Instead of following the specified order, all definitions in the generated migration file are sorted lexicographically by table/definition name, which can cause dependency issues during migration execution.Steps to Reproduce
./schemas/config.toml:db diff -f testsupabase db resetExpected Behavior
TIMESTAMP_generated_migration.sqlshould be generatedschema_pathsconfigurationsupabase db resetshould execute successfully without dependency errorsActual Behavior
schema_pathsordersupabase db resetfails when table names come before function names alphabetically, as functions are defined after tables in the migration file despite the configurationScreenshots
Schema Structure
Configuration
Generated Migration (showing incorrect order)
Environment Information
9ab2a8e41ff24f22b98a4746f4417224Service Versions
15.8.1.030v2.176.1v12.2.3v2.38.0v1.24.7v1.67.42025.06.30-sha-6f5982dv0.89.31.14.22.5.6Impact
This issue prevents proper dependency management in database schemas, leading to failed migrations when objects depend on a specific creation order (e.g., functions that must be created before tables that reference them).