Skip to content

Commit 5f8be31

Browse files
authored
fix: add missing migration and clearing_purpose to internal-account schema tests (#1224)
The nightly slow integration tests were failing because: 1. applyAllMigrations was missing the counterparty rename migration (20260225000002), so counterparty_id column didn't exist 2. All CLEARING account inserts were missing the required clearing_purpose field, violating chk_clearing_purpose_for_clearing_type constraint Both issues were introduced during the asset-agnostic-accounts marathon where task-6 (service rename) and task-7 (counterparty rename) modified the schema but the schema_test.go wasn't fully updated. Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 538edb3 commit 5f8be31

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

services/internal-account/migrations/schema_test.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ func TestSchema_ConstraintsWork(t *testing.T) {
138138
err := db.Exec(`
139139
INSERT INTO internal_account (
140140
account_id, account_code, name, account_type,
141-
instrument_code, dimension, created_by, updated_by
141+
instrument_code, dimension, clearing_purpose, created_by, updated_by
142142
) VALUES (
143143
'ACC-001', 'CLEAR-GBP', 'GBP Clearing Account', 'CLEARING',
144-
'GBP', 'CURRENCY', 'test', 'test'
144+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
145145
)
146146
`).Error
147147
assert.NoError(t, err, "Valid insert should succeed")
@@ -163,10 +163,10 @@ func TestSchema_ConstraintsWork(t *testing.T) {
163163
err = db.Exec(`
164164
INSERT INTO internal_account (
165165
account_id, account_code, name, account_type,
166-
instrument_code, dimension, created_by, updated_by
166+
instrument_code, dimension, clearing_purpose, created_by, updated_by
167167
) VALUES (
168168
'ACC-003', 'INVALID', 'Invalid Dimension', 'CLEARING',
169-
'GBP', 'INVALID_DIM', 'test', 'test'
169+
'GBP', 'INVALID_DIM', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
170170
)
171171
`).Error
172172
assert.Error(t, err, "Invalid dimension should be rejected")
@@ -176,10 +176,10 @@ func TestSchema_ConstraintsWork(t *testing.T) {
176176
err = db.Exec(`
177177
INSERT INTO internal_account (
178178
account_id, account_code, name, account_type,
179-
instrument_code, dimension, status, created_by, updated_by
179+
instrument_code, dimension, status, clearing_purpose, created_by, updated_by
180180
) VALUES (
181181
'ACC-004', 'INVALID', 'Invalid Status', 'CLEARING',
182-
'GBP', 'CURRENCY', 'INVALID_STATUS', 'test', 'test'
182+
'GBP', 'CURRENCY', 'INVALID_STATUS', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
183183
)
184184
`).Error
185185
assert.Error(t, err, "Invalid status should be rejected")
@@ -204,10 +204,10 @@ func TestSchema_ForeignKeyConstraint(t *testing.T) {
204204
err := db.Exec(`
205205
INSERT INTO internal_account (
206206
account_id, account_code, name, account_type,
207-
instrument_code, dimension, created_by, updated_by
207+
instrument_code, dimension, clearing_purpose, created_by, updated_by
208208
) VALUES (
209209
'ACC-FK-TEST', 'FK-TEST', 'FK Test Account', 'CLEARING',
210-
'GBP', 'CURRENCY', 'test', 'test'
210+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
211211
)
212212
`).Error
213213
require.NoError(t, err)
@@ -304,12 +304,17 @@ func TestSchema_AllAccountTypes(t *testing.T) {
304304

305305
for _, accountType := range accountTypes {
306306
accountID := "ACC-TYPE-" + accountType
307+
var clearingPurpose *string
308+
if accountType == "CLEARING" {
309+
cp := "CLEARING_PURPOSE_GENERAL"
310+
clearingPurpose = &cp
311+
}
307312
err := db.Exec(`
308313
INSERT INTO internal_account (
309314
account_id, account_code, name, account_type,
310-
instrument_code, dimension, created_by, updated_by
311-
) VALUES (?, ?, ?, ?, 'GBP', 'CURRENCY', 'test', 'test')
312-
`, accountID, "CODE-"+accountType, accountType+" Account", accountType).Error
315+
instrument_code, dimension, clearing_purpose, created_by, updated_by
316+
) VALUES (?, ?, ?, ?, 'GBP', 'CURRENCY', ?, 'test', 'test')
317+
`, accountID, "CODE-"+accountType, accountType+" Account", accountType, clearingPurpose).Error
313318
assert.NoError(t, err, "Account type %s should be valid", accountType)
314319
}
315320
}
@@ -361,10 +366,10 @@ func TestSchema_UniqueConstraints(t *testing.T) {
361366
err := db.Exec(`
362367
INSERT INTO internal_account (
363368
account_id, account_code, name, account_type,
364-
instrument_code, dimension, created_by, updated_by
369+
instrument_code, dimension, clearing_purpose, created_by, updated_by
365370
) VALUES (
366371
'ACC-UNIQUE', 'UNIQUE-CODE', 'Unique Account', 'CLEARING',
367-
'GBP', 'CURRENCY', 'test', 'test'
372+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
368373
)
369374
`).Error
370375
require.NoError(t, err)
@@ -373,10 +378,10 @@ func TestSchema_UniqueConstraints(t *testing.T) {
373378
err = db.Exec(`
374379
INSERT INTO internal_account (
375380
account_id, account_code, name, account_type,
376-
instrument_code, dimension, created_by, updated_by
381+
instrument_code, dimension, clearing_purpose, created_by, updated_by
377382
) VALUES (
378383
'ACC-UNIQUE', 'DIFFERENT-CODE', 'Another Account', 'CLEARING',
379-
'GBP', 'CURRENCY', 'test', 'test'
384+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
380385
)
381386
`).Error
382387
assert.Error(t, err, "Duplicate account_id should fail")
@@ -400,10 +405,10 @@ func TestSchema_CounterpartyFields(t *testing.T) {
400405
err := db.Exec(`
401406
INSERT INTO internal_account (
402407
account_id, account_code, name, account_type,
403-
instrument_code, dimension, created_by, updated_by
408+
instrument_code, dimension, clearing_purpose, created_by, updated_by
404409
) VALUES (
405410
'ACC-NO-COUNTERPARTY', 'NO-COUNTERPARTY', 'No Counterparty', 'CLEARING',
406-
'GBP', 'CURRENCY', 'test', 'test'
411+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
407412
)
408413
`).Error
409414
assert.NoError(t, err, "Account without counterparty should succeed")
@@ -454,10 +459,10 @@ func TestSchema_SoftDelete(t *testing.T) {
454459
err := db.Exec(`
455460
INSERT INTO internal_account (
456461
account_id, account_code, name, account_type,
457-
instrument_code, dimension, created_by, updated_by
462+
instrument_code, dimension, clearing_purpose, created_by, updated_by
458463
) VALUES (
459464
'ACC-SOFT-DEL', 'SOFT-DEL', 'Soft Delete Test', 'CLEARING',
460-
'GBP', 'CURRENCY', 'test', 'test'
465+
'GBP', 'CURRENCY', 'CLEARING_PURPOSE_GENERAL', 'test', 'test'
461466
)
462467
`).Error
463468
require.NoError(t, err)
@@ -519,6 +524,7 @@ func applyAllMigrations(t *testing.T, db *gorm.DB, migrationsDir string) {
519524
"20260220000001_add_product_type_code.sql",
520525
"20260220000002_add_product_type_index.sql",
521526
"20260225000001_rename_to_internal_account.sql",
527+
"20260225000002_rename_correspondent_to_counterparty.sql",
522528
}
523529
for _, migration := range migrations {
524530
sql, err := readMigrationFile(filepath.Join(migrationsDir, migration))

0 commit comments

Comments
 (0)