SmartTableSync.Scaffold
0.5.2
See the version list below for details.
dotnet tool install --global SmartTableSync.Scaffold --version 0.5.2
dotnet new tool-manifest
dotnet tool install --local SmartTableSync.Scaffold --version 0.5.2
#tool dotnet:?package=SmartTableSync.Scaffold&version=0.5.2
nuke :add-package SmartTableSync.Scaffold --version 0.5.2
SmartTableSync.Scaffold
A command-line tool that reads a parent table's schema and writes the SQL that
SmartTableSync needs, for a person to review and
apply. It never executes anything against a database: it only reads schema metadata and
writes .sql files.
For the whole setup, including which identity applies which script, see the setup guide.
Install
From NuGet, once published:
dotnet tool install --global SmartTableSync.Scaffold
smarttablesync-scaffold --help
From source, without installing:
dotnet run --project SmartTableSync.Scaffold -- --help
Or install your own build as a global tool:
dotnet pack SmartTableSync.Scaffold --output ./nupkg
dotnet tool install --global SmartTableSync.Scaffold --add-source ./nupkg
Commands
| Command | Writes | Apply to | Needs |
|---|---|---|---|
--infrastructure |
00_infrastructure.sql: the tracking tables CustomSyncState, SyncBatchLog, SyncTableConfig |
child, once | nothing |
<Table> [<Table> ...] |
per table: <Table>.sql when the child table doesn't exist yet, or <Table>_AddColumns.sql when the parent has columns the existing child table lacks; <Table>TableType.sql (TVP tables; drops and recreates an out-of-date type first); sp_Sync<Table>Batch.sql or sp_Sync<Table>.sql |
child | both connection strings |
--change-tracking-setup <Table> [...] [--retention-days <N>] |
<Table>_ChangeTrackingSetup.sql: enables Change Tracking on the database (default 2-day retention) and the table, and grants VIEW CHANGE TRACKING to smarttablesync-runtime |
parent, by a DBA | parent connection string |
--rowversion-setup <Table> [...] [--column <Name>] |
<Table>_RowVersionSetup.sql: adds a rowversion column (default RowVer) and its index |
parent, by a DBA | parent connection string |
Every command takes --output <dir>; the default is sql/generated/ under the current
directory.
Name a table outside dbo as schema.Table (sales.Order). Its scripts create the schema in the
child when it's missing and put the table type and procedure in it; their file names start with
the schema (sales.OrderTableType.sql, sales.sp_SyncOrderBatch.sql).
For each table, the per-table command prints the plan it derived, which is the same plan the sync engine derives at runtime:
=== Product ===
MergeStrategy=Tvp, BatchSize=1000, BulkCopyTimeoutSeconds=120, IncrementalStrategy=SqlChangeTracking
Apply the child files in this order: tables (or added columns), table types, procedures.
For an existing child table, the tool compares it with the parent, the same way Auto mode does.
New columns get the _AddColumns.sql script. Changes that could lose data (a changed type or
length, a changed primary key, a removed NOT NULL column, a column that now allows NULL in
the parent but not in the child) are printed as NEEDS A MANUAL CHANGE and left to you. A
decimal or numeric column whose precision or scale differs from the parent also gets
<Table>_AlterColumns.sql, which fixes the column and says how to copy the table again so the
values that were rounded become exact.
The Change Tracking script grants VIEW CHANGE TRACKING to smarttablesync-runtime. If your
runtime identity has another name, change it in the script before applying.
Connection strings
Set as environment variables:
| Variable | Identity | Rights it needs |
|---|---|---|
ParentIntrospectionConnectionString |
parent introspection | on the parent: VIEW DEFINITION, SELECT on the tables, VIEW DATABASE STATE |
ChildProvisioningConnectionString |
child provisioning | on the child: db_ddladmin. The tool only reads the existing child schema (tables, columns, table types) to decide what to write; it never changes anything |
With your own Microsoft Entra sign-in (through Azure CLI, Visual Studio or environment credentials):
$env:ParentIntrospectionConnectionString = "Server=tcp:<server>.database.windows.net,1433;Database=<parent>;Authentication=Active Directory Default;Encrypt=True"
$env:ChildProvisioningConnectionString = "Server=tcp:<server>.database.windows.net,1433;Database=<child>;Authentication=Active Directory Default;Encrypt=True"
With SQL authentication, use User Id=...;Password=... instead of Authentication=....
Settings that change the plan
The tool reads the same settings the sync engine does, from environment variables, so the scripts it writes match what the engine will expect. Set them the same way as for the Function:
| Variable | Effect |
|---|---|
SmartTableSync__TimestampColumns__<Table> |
the datetime column the Timestamp strategy uses (default LastUpdate) |
SmartTableSync__AllowFullRescanFor |
comma-separated large tables allowed to fall back to a full re-scan |
SmartTableSync__IncrementalStrategyOverrides__<Table> |
force SqlChangeTracking, RowVersion, Timestamp or FullRescan for a table |
If a setting can't work for a table, for example a forced strategy the table doesn't support, the tool reports the same error the engine would and writes nothing for that table.
Example
smarttablesync-scaffold --infrastructure --output out/child
smarttablesync-scaffold Product Customer Document --output out/child
smarttablesync-scaffold --change-tracking-setup Product --output out/parent
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
Fixes the quick start in projects created from the template: in 0.5.1 it stopped when publishing
the Function. The library and the scaffold tool are unchanged apart from the version.
### Fixed
- The quick start in a project created from the `smarttablesync-azure` template stopped at
publishing the Function ("Can't determine project language from files"): `func` read the
runtime from `local.settings.json`, which such a project, like a fresh clone, doesn't have.
`deploy.ps1` and the demo's `run-demo.ps1` now pass `--dotnet-isolated`.
### Changed
- Turning on Change Tracking is now the first step of the quick start, in the README's *Get
started*, the NuGet guide and the template's READMEs.
### Upgrading
Nothing to change in the databases or settings. For a project created from the 0.5.1 template,
either add `--dotnet-isolated` to the `func azure functionapp publish` line in
`quickstart/deploy.ps1`, or run `dotnet new update` and create the project again.
### Tested
- Both ways in the README's *Get started*, from nuget.org in empty folders:
- **Own app:** a worker with the SmartTableSync package and SQL Server in Docker, with Change
Tracking turned on as the guide says. The first run created the child table and copied
1,000 rows; after updates, an insert and a delete in the parent, the next run synced 11 rows
and 1 delete.
- **Azure Function:** the template, Change Tracking turned on as the guide says, and
`deploy.ps1` with connection strings on two Azure SQL databases. The dry run, the setup
(Terraform, publishing the Function, the first sync: 500 and 300 rows), `-SyncNow` after
updates, inserts and a delete in the parent, and `-Destroy` all completed, with the child
matching the parent row for row.
- Unit and integration tests (298 and 72) pass.
Full changelog: https://github.com/Sidorus/SmartTableSync/blob/main/CHANGELOG.md