-- Migration Doctor snapshot, SQL export: group names from all active directories (complete list; REST caps it). -- 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 groups.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 groups.sql -o export/groups.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; SELECT (SELECT g.group_name AS [name] FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES) FROM $(JIRA_SCHEMA).cwd_group g JOIN $(JIRA_SCHEMA).cwd_directory d ON d.id = g.directory_id AND d.active = 1 WHERE g.active = 1 AND d.directory_position = ( SELECT MIN(d2.directory_position) FROM $(JIRA_SCHEMA).cwd_group g2 JOIN $(JIRA_SCHEMA).cwd_directory d2 ON d2.id = g2.directory_id AND d2.active = 1 WHERE g2.lower_group_name = g.lower_group_name AND g2.active = 1) ORDER BY g.lower_group_name;