@@ -307,15 +307,16 @@ Environment variables override values from the config file when no explicit `--p |
307 | 307 |
|
308 | 308 | **Advanced** (shown in `help --all`): |
309 | 309 |
|
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 | |
319 | 320 |
|
320 | 321 | Note: `sscli sessions` filters by client host name using `--client-host`. `--host` is reserved as an alias for `--server`. |
321 | 322 |
|
@@ -351,13 +352,57 @@ Each command returns a stable top-level object: |
351 | 352 | | `describe` | `{ object: {schema, name, type}, columns, ddl?, indexes?, triggers?, foreignKeys?, constraints? }` | |
352 | 353 | | `table-data` | `{ table, columns, rows, total, offset, limit, hasMore, nextOffset }` | |
353 | 354 | | `sql` | `{ success, batches, resultSets, csvPaths? }` | |
| 355 | +| `compare` | `{ modules, indexes, constraints, tables }` when `--summary`; `{ source, target }` snapshots with full metadata when `--json` without `--summary` | |
354 | 356 |
|
355 | 357 | Errors (stderr): |
356 | 358 |
|
357 | 359 | ```json |
358 | 360 | { "error": { "message": "...", "kind": "Config|Connection|Query|Internal" } } |
359 | 361 | ``` |
360 | 362 |
|
| 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 | + |
361 | 406 | ## Testing |
362 | 407 |
|
363 | 408 | ```bash |
|