Skip to content

db diff -f <name> ignores schema_paths order from config.toml #3854

Description

@DahTach

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

  1. Create a nested schema structure in ./schemas/
  2. Define tables and functions in different directories:
    ./schemas/dir_name_1/function1.sql
    ./schemas/dir_name_2/table1.sql
    
  3. Configure the desired order in config.toml:
    [db.migrations]
    schema_paths = [
      "./schemas/dir_name_1/function1.sql",
      "./schemas/dir_name_2/table1.sql"
    ]
  4. Run db diff -f test
  5. Examine the generated migration file
  6. 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

Schema directory structure

Configuration

config.toml schema_paths configuration

Generated Migration (showing incorrect order)

Generated migration file with lexicographic ordering

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions