Skip to content

Deterministic ordering for SchemaObjectType extract output #795

@pedroz666

Description

@pedroz666

Is your feature request related to a problem? Please describe.

When using sqlpackage with:

sqlpackage /Action:Extract /p:ExtractTarget=SchemaObjectType

the generated SQL files are not fully deterministic.

Even when there are no actual schema changes in the database, repeated exports may generate differences in:

  • permissions (GRANT, DENY, REVOKE)
  • indexes
  • constraints
  • other dependent object definitions

The order of these definitions inside object files may change between exports.

This creates unnecessary noise in Git commits and makes code reviews and schema comparisons more difficult. In repositories where database schemas are versioned as individual SQL files (schema/objecttype/object.sql structure), it becomes hard to identify real changes versus serialization-order differences.


Describe the solution you'd like

Add an option for deterministic/stable serialization when using ExtractTarget=SchemaObjectType.

For example:

  • stable ordering of permissions
  • stable ordering of indexes
  • stable ordering of constraints
  • deterministic ordering of all generated object definitions

The same database schema state should always generate identical output files.

Possible implementation ideas:

  • alphabetical ordering
  • dependency-aware but deterministic ordering
  • optional /p:DeterministicOutput=True switch

This would significantly improve Git-based workflows, code reviews, CI/CD pipelines, and schema versioning scenarios.


Describe alternatives you've considered

Current alternatives include:

  • using external post-processing scripts to reorder sections
  • using schema compare tools instead of Git diffs
  • ignoring noisy sections in comparisons
  • switching to third-party tooling

However, these approaches either:

  • add additional maintenance complexity,
  • require custom tooling,
  • or reduce visibility into real schema changes.

A built-in deterministic export mode in sqlpackage would provide a cleaner and more reliable solution.


Additional context

This issue is especially visible when using:

  • ExtractTarget=SchemaObjectType
  • repositories storing one file per database object
  • Git-based source control workflows

The generated folder structure is very convenient for development and review, but unstable ordering inside files introduces unnecessary diff noise.

The request is not related to SQL formatting/style changes. The main concern is deterministic ordering of generated definitions and metadata sections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    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