Commit 1809bce
committed
BACPAC loader Phases C+D+E — constraints, indexes, programmable objects. Dispatcher restructured from a
**New emitters**:
- `EmitKeyConstraint` — shared PK+UQ via an `isPrimary` flag (PK defaults CLUSTERED, UQ defaults NONCLUSTERED). Unnamed UQ constraints (the AW pattern where the auto-generated name lives in a SysCommentsObjectAnnotation rather than the element's Name attribute) drop the `CONSTRAINT name` segment and let the simulator allocate.
- `EmitForeignKeyConstraint` — maps DACFx's `OnDeleteAction`/`OnUpdateAction` integer enum (0=NO ACTION/omitted, 1=CASCADE, 2=SET NULL, 3=SET DEFAULT) via `TranslateReferentialAction`.
- `EmitCheckConstraint` / `EmitDefaultConstraint` — pass the CDATA expression script verbatim to the simulator's already-shipped parsers.
- `EmitIndex` — `CREATE [UNIQUE] [CLUSTERED|NONCLUSTERED] INDEX … ON … (…) [INCLUDE (…)]`; pre-built `viewNames` HashSet lets indexed-view targets skip cleanly (indexed views need SCHEMABINDING machinery the simulator doesn't model). Wrapped in try/catch so indexes referencing not-yet-loaded computed columns degrade to Skipped with the simulator's diagnostic rather than aborting the whole load.
- `EmitProgrammableObject` — universal emitter for views/scalar funcs/multi-stmt TVFs/procs/DML triggers/DDL triggers. Uses the canonical `HeaderContents` from each element's `SysCommentsObjectAnnotation` and concatenates the body (`QueryScript` for views, `BodyScript` everywhere else). Transparently follows the `FunctionBody → SqlScriptFunctionImplementation` indirection for both scalar and multi-statement functions where the annotation lives one level deeper.
**Shared XML helpers** factored out: `ReadScriptProperty` (CDATA body bodies), `ReadSingleReference` (one-Entry relationship → Name), `ReadMultipleReferences` (N-Entry relationship → ordered list), `Leaf` (bracketed leaf of a qualified name — constraint and index names arrive 2-part `[schema].[name]` but ALTER TABLE ADD CONSTRAINT / CREATE INDEX expect the unqualified form).
**Simulator bug fix** — `NOT FOR REPLICATION` in CREATE TRIGGER and CREATE PROCEDURE has been broken since those features shipped: `Replication` is in the reserved `Keyword` enum, so the tokenizer returns it as `ReservedKeyword`, but both parsers were pattern-matching only `UnquotedString { ContextualKeyword: ContextualKeyword.Replication }`. Test coverage missed this because no existing test exercises the `NOT FOR REPLICATION` clause. Patched both sites to accept either token form. Surfaced via 4 AW DML triggers (`HumanResources.dEmployee`, `Person.iuPerson`, `Purchasing.dVendor`, and one more) and 2 AW procs that use the clause.
**AW load coverage after this bundle**: 5/5 schemas, 71/71 tables (with simple columns), 6/6 UDDTs, 71/71 PKs, 1/1 UQ, 90/90 FKs (2 CASCADE), 89/89 CHECKs, 152/152 DEFAULTs, 89/95 indexes (2 indexed-views + 4 computed-col-referencing deferred to Skipped), 11/20 views, 8/10 procs, 10/11 functions, 10/10 DML triggers, 1/1 DDL trigger.
**Documented remaining gaps** on `BacpacLoadResult.Skipped`: CROSS APPLY in `vJobCandidate`-family view bodies (parser rejects); unbracketed UDDT `dbo.Flag` as a procedure parameter type (1-part alias resolution misses on this path); 3 scalar UDFs hit `RETURN`-with-value-in-unsupported-context. Each surfaces as a future simulator-feature bundle rather than a loader concern. Computed columns, extended properties, permissions, full-text catalog/index, and XML schema collections + indexes are all still on Skipped pending their own phases.bool isPhase1 to a phase int (1-7) driven by a top-level loop in Apply; Skipped-recording deferred to the last phase so each unhandled type reports once. Phase ordering encodes the AW dependency graph: 1=schemas/UDDTs/options, 2=tables, 3=PK/UQ/CHECK/DEFAULT, 4=FK, 5=indexes, 6=views, 7=functions/procs/DML triggers/DDL triggers.1 parent b20bb22 commit 1809bce
4 files changed
Lines changed: 567 additions & 37 deletions
File tree
- SqlServerSimulator.Tests.Internal/Storage
- SqlServerSimulator
- Simulation
- Storage/Bacpac
Lines changed: 178 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
| 86 | + | |
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
95 | 271 | | |
96 | 272 | | |
97 | 273 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
336 | 342 | | |
| 343 | + | |
337 | 344 | | |
338 | 345 | | |
339 | 346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
116 | 122 | | |
| 123 | + | |
117 | 124 | | |
118 | 125 | | |
119 | 126 | | |
| |||
0 commit comments