MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestIdentityColumnHandling

Function TestIdentityColumnHandling

backend/plugin/parser/tsql/backup_test.go:163–190  ·  view source on GitHub ↗

TestIdentityColumnHandling validates that our implementation correctly handles IDENTITY columns This test verifies: 1. The backup uses simple SELECT INTO (copying IDENTITY properties naturally) 2. The restore.go handles IDENTITY_INSERT during rollback

(t *testing.T)

Source from the content-addressed store, hash-verified

161// 1. The backup uses simple SELECT INTO (copying IDENTITY properties naturally)
162// 2. The restore.go handles IDENTITY_INSERT during rollback
163func TestIdentityColumnHandling(t *testing.T) {
164 a := require.New(t)
165
166 // Test case: DELETE from a table that typically has IDENTITY columns
167 input := `DELETE FROM positions WHERE position_id = 1;`
168
169 result, err := TransformDMLToSelect(context.Background(), base.TransformContext{},
170 input, "db", "backupDB", "rollback")
171 a.NoError(err)
172 a.Len(result, 1)
173
174 // Verify the generated SQL uses simple SELECT INTO
175 stmt := result[0].Statement
176
177 // Key assertions about the generated SQL:
178 // 1. Uses simple SELECT INTO
179 a.Contains(stmt, "SELECT * INTO [backupDB].[dbo].[rollback_positions_db]")
180
181 // 2. Selects from the original table with proper bracketing
182 a.Contains(stmt, "SELECT [db].[dbo].[positions].* FROM")
183
184 // 3. Includes the WHERE clause
185 a.Contains(stmt, "WHERE position_id = 1")
186
187 // The approach:
188 // Backup: Simple SELECT * INTO backup_table (copies IDENTITY property naturally)
189 // Restore: restore.go handles IDENTITY_INSERT ON/OFF for rollback
190}
191
192// TestBackupStatementStructure validates the structure of backup statements
193func TestBackupStatementStructure(t *testing.T) {

Callers

nothing calls this directly

Calls 2

LenMethod · 0.80
TransformDMLToSelectFunction · 0.70

Tested by

no test coverage detected