-- Migration Doctor snapshot, SQL export: all dashboards with owner username. -- Read-only: a single SELECT, no writes, no temporary tables. Output: one JSON object per line. -- Run (read-only) with sqlcmd and save the output as dashboards.jsonl. JIRA_SCHEMA is the schema of the -- Jira tables (usually jiraschema, sometimes dbo): -- sqlcmd -S DBHOST -d JIRADB -E -v JIRA_SCHEMA=jiraschema -y 0 -f 65001 -i dashboards.sql -o export/dashboards.jsonl -- (-E uses Windows authentication; use -U READONLY_USER and let sqlcmd prompt for the password otherwise.) -- Then pass the export directory to the snapshot script: --sql-export-dir export (bash) or -SqlExportDir export (PowerShell). SET NOCOUNT ON; WITH owner_name AS ( SELECT a.user_key, COALESCE((SELECT TOP 1 u.user_name FROM $(JIRA_SCHEMA).cwd_user u JOIN $(JIRA_SCHEMA).cwd_directory d ON d.id = u.directory_id AND d.active = 1 WHERE u.lower_user_name = a.lower_user_name ORDER BY d.directory_position), a.lower_user_name) AS user_name FROM $(JIRA_SCHEMA).app_user a ) SELECT (SELECT pp.id AS [id], pp.pagename AS [name], CASE WHEN pp.username IS NULL THEN NULL ELSE COALESCE(o.user_name, pp.username) END AS [owner] FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES) FROM $(JIRA_SCHEMA).portalpage pp LEFT JOIN owner_name o ON o.user_key = pp.username ORDER BY pp.id;