wise-coders / dbschema

DbSchema Database Designer
https://dbschema.com
67 stars 3 forks source link

Schema DDL does not respect function ordering #66

Open ghost opened 2 years ago

ghost commented 2 years ago
  1. Please check DbSchema Help / Output logs for errors.
09:00:21 Import task done.
09:00:21 REVERSE ENGINEERED 13 TABLES FROM AzureSQL.
09:04:00 > exportSchemaScript
09:04:00 Dialog Export Schema & Data
09:04:19 > chooseFile
09:04:28 > ok
09:04:28 Dialog Select Schemas & Tables to Include
09:12:55 > outputLogs
09:12:55 Dialog Output Logs
  1. Please include the DbSchema version, operating system and used database

DbSchema: 9.0.0 Azure SQL

  1. The steps to reproduce this issue

Create functions, which depend on each other

CREATE OR ALTER FUNCTION security.ufnHasDatasetAccess(@DatasetID int)
    RETURNS TABLE
WITH SCHEMABINDING
AS
    RETURN
        select 1 as able from security.ufnHasIndirectAccess(@DatasetID)
GO

CREATE   FUNCTION security.ufnHasIndirectAccess(@ParentID int)
    RETURNS TABLE
WITH SCHEMABINDING
AS
    RETURN
        SELECT 1 as able
GO

Go to DBSchema tool: Schema -> Generate Schema DDL. Produced ordering is incorrect, since security.ufnHasDatasetAccess gets put first instead of schema.ufnHasIndirectAccess

ghost commented 2 years ago

I think the generated scripts are also missing GO after function definition