Going further

Import on a schedule (cron)

A recurring job keeps the documentation current without anyone opening SSMS. Set it up once. See Import a schema first for the security notes.

  1. Wrap the extractor as a stored procedure in your own database, so the job runs one line instead of piping the whole script. The demo workspace documents this flow — load the demo and open the ZestreaDB extraction flow to see what it looks like.

  2. Under Admin → Automation Keys, create a key scoped to this workspace, and give it to the job as ZESTREA_KEY.

  3. Grant the service account GRANT VIEW DEFINITION and GRANT SELECT ON sys.sql_expression_dependencies.

    That is exactly reading object definitions and dependency metadata, nothing else — the sentence that gets the grant approved.

  4. Run this on your schedule — pick your authentication and copy the whole command:

    SQL login

    SERVER=your-server.example.com,1433
    DATABASE=YourDatabase
    SQLUSER=your-user
    SQLPASS=your-password
    ZESTREA_KEY=your-api-key
    sqlcmd -S "$SERVER" -U "$SQLUSER" -P "$SQLPASS" -C -d "$DATABASE" \
      -Q "EXEC dbo.ZestreaDB_ExtractSchema" \
      -h -1 -W -y 0 -o /tmp/schema.json \
    && curl -X POST https://zestreadb.com/api/v1/ingest/schema \
      -H "Authorization: Bearer $ZESTREA_KEY" \
      -H "Content-Type: application/json" \
      --data-binary @/tmp/schema.json

    Windows auth

    SERVER=your-server.example.com,1433
    DATABASE=YourDatabase
    ZESTREA_KEY=your-api-key
    sqlcmd -S "$SERVER" -E -C -d "$DATABASE" \
      -Q "EXEC dbo.ZestreaDB_ExtractSchema" \
      -h -1 -W -y 0 -o /tmp/schema.json \
    && curl -X POST https://zestreadb.com/api/v1/ingest/schema \
      -H "Authorization: Bearer $ZESTREA_KEY" \
      -H "Content-Type: application/json" \
      --data-binary @/tmp/schema.json

    Entra ID

    SERVER=your-server.example.com,1433
    DATABASE=YourDatabase
    ZESTREA_KEY=your-api-key
    sqlcmd -S "$SERVER" -G -C -d "$DATABASE" \
      -Q "EXEC dbo.ZestreaDB_ExtractSchema" \
      -h -1 -W -y 0 -o /tmp/schema.json \
    && curl -X POST https://zestreadb.com/api/v1/ingest/schema \
      -H "Authorization: Bearer $ZESTREA_KEY" \
      -H "Content-Type: application/json" \
      --data-binary @/tmp/schema.json

    The -h -1 -W -y 0 flags stop sqlcmd formatting the output for a terminal.

Prefer not to grant those rights? An alternative is EXECUTE AS OWNER on the procedure, so the caller needs only EXECUTE — at the cost of the procedure running elevated, which some teams will not allow.