fix(sqlserver): preserve IDENTITY columns when copying table (#1691) - #1918
Conversation
openai0229
left a comment
There was a problem hiding this comment.
The current implementation is not safe for the SQL Server table shapes claimed by this PR.
SET IDENTITY_INSERT ... ONis executed unconditionally and fails for tables without an identity column.INSERT INTO target SELECT * FROM sourceis invalid when computed columns or rowversion/timestamp columns are present; the copy needs explicit compatible column lists.- Global
ddl.replace("[source]", "[target]")can rewrite references outside the object name and does not safely regenerate constraint/index names.
Please redesign this around parsed metadata and explicit column/object lists, then add SQL Server integration tests for tables with no identity, identity, computed columns, rowversion, defaults, constraints, and indexes. The PR should not claim those objects are preserved until the tests prove it.
8bbb63c to
06fb88f
Compare
|
Redesigned the copyTable implementation per review feedback: 1. Conditional IDENTITY_INSERT — no longer executed unconditionally. Now queries 2. Explicit column list — instead of
Uses 3. Safe table name replacement — instead of global 4. Rebased on current main. |
…nd#1691) Use Chat2DBContext.getDbMetaData().tableDDL() to generate proper CREATE TABLE DDL that preserves IDENTITY, computed columns, constraints, indexes, etc. For data copying, wrap INSERT INTO...SELECT with SET IDENTITY_INSERT ON/OFF to allow explicit values in identity columns. The previous SELECT * INTO approach silently dropped IDENTITY properties.
06fb88f to
3e9f21a
Compare
openai0229
left a comment
There was a problem hiding this comment.
Maintainer follow-up now covers explicit column selection, identity ownership and cleanup, SQL-aware DDL/batch rewriting, identifier handling, and focused regression tests. The previous blocking concerns are resolved.
openai0229
left a comment
There was a problem hiding this comment.
Maintainer follow-up complete: verified identifier normalization, constraint quoting, referential-action preservation, and SQL Server grammar ordering. Tools (26), SPI (54), and SQL Server (37) tests pass.
Summary
Preserve SQL Server
IDENTITYsemantics when copying a table while keeping the generated DDL and data-copy SQL valid for real-world schemas.Changes
tableDDL()and rewrite the target schema/table references in table, index, extended-property, and self-referencing foreign-key DDL.GObatches without treating strings, comments, or quoted identifiers as separators, including the legacygo<TAB>exec sp_addextendedpropertyform.TIMESTAMP, andROWVERSIONcolumns.IDENTITY_INSERTonly for tables that actually contain an identity column, and always attempt to turn it off after a successfulON, preserving cleanup failures as suppressed exceptions.BigDecimal, normalize a single bracket-quoted table identifier at the copy boundary, and avoid invalid JDBC size metadata forTIMESTAMP/ROWVERSION.ON DELETEandON UPDATEactions in SQL Server grammar order.Validation
git diff --checkpassed.Related to #1691