GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add compare command and drift reporting · jwcraig/sql-server-cli@d2f730a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Cargo.lock
  • Cargo.toml
  • README.md
  • assets
    • SKILL.md.template
    • sscli-compare.1.md
  • src
    • cli
      • args.rs
      • mod.rs
    • commands
      • compare.rs
      • mod.rs
  • tests
    • help_test.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Cargo.lock‎

Copy file name to clipboardExpand all lines: Cargo.lock
+99Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎Cargo.toml‎

Copy file name to clipboardExpand all lines: Cargo.toml
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sscli"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
edition = "2024"
55
rust-version = "1.85"
66
description = "Agent-friendly token efficient SQL Server CLI tool for database inspection"
@@ -26,6 +26,9 @@ csv = "1.3"
2626
dotenvy = "0.15.7"
2727
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] }
2828
semver = "1.0"
29+
regex = "1.10"
30+
similar = "2.4"
31+
chrono = { version = "0.4", features = ["clock"] }
2932

3033
[dev-dependencies]
3134
tokio-test = "0.4"
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+54-9Lines changed: 54 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,16 @@ Environment variables override values from the config file when no explicit `--p
307307

308308
**Advanced** (shown in `help --all`):
309309

310-
| Command | Purpose |
311-
| -------------- | ------------------------------------- |
312-
| `indexes` | Index details with usage stats |
313-
| `foreign-keys` | Table relationships |
314-
| `stored-procs` | List and execute read-only procedures |
315-
| `sessions` | Active database sessions |
316-
| `query-stats` | Top cached queries by resource usage |
317-
| `backups` | Recent backup history |
318-
| `integrations` | Install agent skills/extensions |
310+
| Command | Purpose |
311+
| -------------- | ---------------------------------------------- |
312+
| `indexes` | Index details with usage stats |
313+
| `foreign-keys` | Table relationships |
314+
| `stored-procs` | List and execute read-only procedures |
315+
| `sessions` | Active database sessions |
316+
| `query-stats` | Top cached queries by resource usage |
317+
| `backups` | Recent backup history |
318+
| `compare` | Schema drift detection between two connections |
319+
| `integrations` | Install agent skills/extensions |
319320

320321
Note: `sscli sessions` filters by client host name using `--client-host`. `--host` is reserved as an alias for `--server`.
321322

@@ -351,13 +352,57 @@ Each command returns a stable top-level object:
351352
| `describe` | `{ object: {schema, name, type}, columns, ddl?, indexes?, triggers?, foreignKeys?, constraints? }` |
352353
| `table-data` | `{ table, columns, rows, total, offset, limit, hasMore, nextOffset }` |
353354
| `sql` | `{ success, batches, resultSets, csvPaths? }` |
355+
| `compare` | `{ modules, indexes, constraints, tables }` when `--summary`; `{ source, target }` snapshots with full metadata when `--json` without `--summary` |
354356

355357
Errors (stderr):
356358

357359
```json
358360
{ "error": { "message": "...", "kind": "Config|Connection|Query|Internal" } }
359361
```
360362

363+
## compare (schema drift)
364+
365+
Detects drift between two profiles or explicit connection strings.
366+
367+
Synopsis:
368+
369+
```
370+
sscli compare --target <profile> [--source <profile>] [--schema web --schema dbo] \
371+
[--summary|--json] [--ignore-whitespace] [--strip-comments] \
372+
[--object dbo.ProcName] [--apply-script [path|-]] [--include-drops]
373+
```
374+
375+
- `--target/--right` (required): profile to treat as the environment you want to align.
376+
- `--source/--left`: reference profile (defaults to global `--profile` or config default).
377+
- `--source-connection/--left-connection`, `--target-connection/--right-connection`: override profile with a connection string (URL or ADO-style `Server=...;Database=...`).
378+
- `--schema/--schemas`: limit to specific schemas (repeatable or comma-separated).
379+
- `--object`: emit unified diff for a single module (proc/view/function/trigger).
380+
- `--ignore-whitespace`, `--strip-comments`: normalize noise before diffing definitions.
381+
- `--summary`: compact drift counts; `--pretty` renders text; `--json` renders JSON.
382+
- `--apply-script [path|-]`: generate SQL to align target to source; default path `db-apply-diff-YYYYMMDD-HHMMSS.sql` in cwd; use `-` for stdout.
383+
- `--include-drops`: include DROP statements (disabled by default).
384+
- Profiles are the names in your `.sql-server/config.*` (e.g., `dev`, `stage`, `prod`). `--source/--target` expect those names.
385+
386+
Examples:
387+
388+
```bash
389+
# Summary with profile names
390+
sscli compare --target prod --summary
391+
392+
# Object diff ignoring whitespace
393+
sscli compare --target prod --object dbo.MyProc --ignore-whitespace
394+
395+
# Apply script to stdout
396+
sscli compare --target prod --apply-script - --include-drops
397+
398+
# Using explicit connection strings instead of profiles
399+
sscli compare --source-connection "Server=dev,1433;Database=app;User ID=sa;Password=..." \
400+
--target-connection "sqlserver://user:pass@prod:1433/app" \
401+
--summary
402+
```
403+
404+
Exit codes: `0` = no drift, `3` = drift detected (summary/object/apply modes), `1` = error.
405+
361406
## Testing
362407

363408
```bash
Collapse file

‎assets/SKILL.md.template‎

Copy file name to clipboardExpand all lines: assets/SKILL.md.template
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,31 @@ sscli sql "SELECT TOP 10 * FROM <TableName/ViewName>"
2525

2626
- `sscli sql` enforces read-only SQL (SELECT/CTE + allowlist).
2727
- To run write queries, use `--allow-write` and confirm intent.
28+
29+
## Compare (schema drift)
30+
31+
Use `compare` to spot differences between environments. It is read-only and safe.
32+
33+
Examples:
34+
35+
```bash
36+
# Summary table across modules/tables/indexes/constraints
37+
sscli compare --target prod --summary # 'prod' is a profile name from .sql-server/config.*
38+
39+
# Object diff (unified) ignoring whitespace
40+
sscli compare --target prod --object dbo.MyProc --ignore-whitespace # prod is a profile name
41+
42+
# Apply script to stdout (align target to source), include drops
43+
sscli compare --target prod --apply-script - --include-drops
44+
45+
# Use explicit connections instead of profiles
46+
sscli compare --source-connection "Server=dev,1433;Database=app;User ID=sa;Password=..." \
47+
--target-connection "sqlserver://user:pass@prod:1433/app" \
48+
--summary
49+
```
50+
51+
Flags worth knowing:
52+
- `--schema/--schemas` limit to specific schemas
53+
- `--strip-comments` remove comments before diffing
54+
- `--compact` restore the terse summary lists (default is tabular)
55+
- `--apply-script [path|-]` writes `db-apply-diff-YYYYMMDD-HHMMSS.sql` by default
Collapse file

‎assets/sscli-compare.1.md‎

Copy file name to clipboard
+70Lines changed: 70 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SSCLI-COMPARE(1)
2+
3+
## NAME
4+
5+
sscli compare - detect schema drift between two SQL Server connections
6+
7+
## SYNOPSIS
8+
9+
`sscli compare --target <profile> [--source <profile>] [--schema <name> ...] [options]`
10+
11+
## DESCRIPTION
12+
13+
`compare` pulls metadata from two SQL Server connections (profiles or explicit
14+
connection strings), normalizes definitions, and reports drift. It can emit a
15+
summary, a unified diff for a single object, or a SQL apply script to align
16+
the target with the source.
17+
18+
## OPTIONS
19+
20+
- `--target`, `--right` **PROFILE**
21+
Required. Profile name from `.sql-server/config.*` to treat as the environment you want to align (e.g., `prod`).
22+
23+
- `--source`, `--left` **PROFILE**
24+
Reference profile (e.g., `dev`, `stage`). Defaults to the global `--profile` or config default.
25+
26+
- `--source-connection`, `--left-connection` **CONN**
27+
Override the source profile with a connection string (URL or ADO style).
28+
29+
- `--target-connection`, `--right-connection` **CONN**
30+
Override the target profile with a connection string.
31+
32+
- `--schema`, `--schemas` **NAME[,NAME...]**
33+
Limit drift detection to specific schemas (repeat or comma-separated).
34+
35+
- `--object` **schema.name|name**
36+
Focus on a single module (proc/view/function/trigger) and emit a unified diff.
37+
38+
- `--summary`
39+
Output a compact JSON or pretty/markdown summary instead of full snapshots.
40+
41+
- `--pretty`
42+
Pretty text summary (with `--summary`). Honors global output format.
43+
44+
- `--ignore-whitespace`
45+
Collapse whitespace before comparing definitions.
46+
47+
- `--strip-comments`
48+
Remove `/* ... */` and `-- ...` comments before comparing.
49+
50+
- `--apply-script` `[path|-]`
51+
Generate SQL to align target to source. Default path:
52+
`db-apply-diff-YYYYMMDD-HHMMSS.sql` in the current directory. Use `-` for stdout.
53+
54+
- `--include-drops`
55+
Include DROP statements for objects missing from the source.
56+
57+
## EXIT STATUS
58+
59+
0 on no drift, 3 when drift is detected (summary/object/apply modes), 1 on error.
60+
61+
## EXAMPLES
62+
63+
Compare default profile to prod and emit summary:
64+
`sscli compare --target prod --summary --pretty`
65+
66+
Diff a single procedure, ignoring whitespace:
67+
`sscli compare --target prod --object dbo.GetUsers --ignore-whitespace`
68+
69+
Generate apply script to stdout:
70+
`sscli compare --target prod --apply-script - --include-drops`

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.