|
Lightweight 0.20261105.1
|
Opt-in behavioural knobs that the ToSql migration-plan renderer honours.
More...
#include <MigrationPlan.hpp>
Classes | |
| struct | ColumnKey |
| struct | TableKey |
| Tables for which the lookup has already been attempted, so we don't re-query for every INSERT against the same table. More... | |
Public Types | |
| enum class | WidthUnit : uint8_t { Characters , Bytes } |
| How a column's declared width is counted. The truncation layer must match the server's interpretation: a VARCHAR(100) on MSSQL holds 100 bytes, but an NVARCHAR(100) holds 100 characters. Truncating to 100 characters when the server budget is 100 bytes still overflows on multi-byte source data. More... | |
Public Attributes | |
| bool | lupTruncate = false |
| bool | fkMatchReferencedText = false |
| std::map< ColumnKey, ColumnWidth > | columnWidths |
| Cache of declared character widths, populated lazily as plan elements render. | |
| std::map< ColumnKey, SqlColumnTypeDefinition > | textColumnTypes |
| std::map< ColumnKey, SqlNullable > | columnNullability |
| std::function< void(MigrationRenderContext &, std::string_view, std::string_view)> | widthLookup |
Optional fallback that fetches column widths for a (schema, table) from the live database when the cache has no entry for it. | |
| std::set< TableKey > | lookupAttempted |
Tables for which widthLookup has already been called; prevents repeat queries. | |
| std::string | activeMigrationTitle |
Identity of the migration currently being rendered. Set by MigrationManager::ApplySingleMigration before ToSql is called for each step so warnings (e.g. lup-truncate) can attribute themselves to the offending migration. Empty / zero when rendering happens outside a migration run (e.g. unit tests calling ToSql directly). | |
| std::uint64_t | activeMigrationTimestamp = 0 |
| Timestamp of the migration currently being rendered (0 outside a migration run). | |
Opt-in behavioural knobs that the ToSql migration-plan renderer honours.
When a profile declares a compat: flag (see Lightweight::Config::CompatFlags), dbtool / dbtool-gui construct one of these and pass it alongside the formatter so migration rendering can diverge from strict behaviour per-run.
The context is mutable across successive ToSql calls within the same migration run: it accumulates a column-width cache populated from CreateTable / AlterTable steps as they are rendered, so later Insert / Update steps can truncate oversize values without a server round-trip.
Default-constructed instances are strict (no truncation, no logging); this is the shape used by code paths that don't care about compat, so existing callers keep their behaviour.
Definition at line 602 of file MigrationPlan.hpp.
|
strong |
How a column's declared width is counted. The truncation layer must match the server's interpretation: a VARCHAR(100) on MSSQL holds 100 bytes, but an NVARCHAR(100) holds 100 characters. Truncating to 100 characters when the server budget is 100 bytes still overflows on multi-byte source data.
Definition at line 635 of file MigrationPlan.hpp.
| bool Lightweight::MigrationRenderContext::lupTruncate = false |
When true, string values in Insert / Update steps are truncated to the destination column's declared character width and the truncation is logged via SqlLogger::OnWarning. Mirrors LUpd's client-side clipping behaviour; see Lightweight::Config::CompatFlagLupTruncate.
Definition at line 608 of file MigrationPlan.hpp.
| bool Lightweight::MigrationRenderContext::fkMatchReferencedText = false |
When true (and the formatter distinguishes narrow and wide text), a foreign-key column declared by a CreateTable / AlterTable step is rendered with the narrow/wide variant of the referenced column's actual type when the two differ only in that respect. A foreign-key column that already exists in the database is retyped with an ALTER COLUMN ahead of the foreign-key command, keeping its nullability. See CompatFlagFkMatchReferencedTextName.
Definition at line 616 of file MigrationPlan.hpp.
| std::map<ColumnKey, ColumnWidth> Lightweight::MigrationRenderContext::columnWidths |
Cache of declared character widths, populated lazily as plan elements render.
Definition at line 648 of file MigrationPlan.hpp.
| std::map<ColumnKey, SqlColumnTypeDefinition> Lightweight::MigrationRenderContext::textColumnTypes |
Per-column text types (Char / NChar / Varchar / NVarchar only), from steps rendered so far and from widthLookup. Consulted by fkMatchReferencedText.
Definition at line 652 of file MigrationPlan.hpp.
| std::map<ColumnKey, SqlNullable> Lightweight::MigrationRenderContext::columnNullability |
Nullability of the columns in textColumnTypes, kept alongside them so an ALTER COLUMN that fkMatchReferencedText emits for an existing foreign-key column preserves it.
Definition at line 657 of file MigrationPlan.hpp.
| std::function<void(MigrationRenderContext&, std::string_view , std::string_view )> Lightweight::MigrationRenderContext::widthLookup |
Optional fallback that fetches column widths for a (schema, table) from the live database when the cache has no entry for it.
The renderer calls this once per (schema, table) it can't satisfy from columnWidths. Implementations should issue a single INFORMATION_SCHEMA.COLUMNS (or equivalent) query and write every char/varchar column's declared width back into columnWidths. They may also write a sentinel (e.g. an empty entry) when the table doesn't exist, so the renderer doesn't keep retrying. Default-empty means "no fallback" — i.e. only widths declared by the same migration plan are considered.
Definition at line 669 of file MigrationPlan.hpp.
| std::set<TableKey> Lightweight::MigrationRenderContext::lookupAttempted |
Tables for which widthLookup has already been called; prevents repeat queries.
Definition at line 681 of file MigrationPlan.hpp.
| std::string Lightweight::MigrationRenderContext::activeMigrationTitle |
Identity of the migration currently being rendered. Set by MigrationManager::ApplySingleMigration before ToSql is called for each step so warnings (e.g. lup-truncate) can attribute themselves to the offending migration. Empty / zero when rendering happens outside a migration run (e.g. unit tests calling ToSql directly).
Definition at line 688 of file MigrationPlan.hpp.
| std::uint64_t Lightweight::MigrationRenderContext::activeMigrationTimestamp = 0 |
Timestamp of the migration currently being rendered (0 outside a migration run).
Definition at line 690 of file MigrationPlan.hpp.