Skip to content

Commit 080e146

Browse files
committed
tapdb: renumber migrations after rebase onto main
Main introduced 000060_asset_transfers_superseded, colliding with this branch's 000060_unique_pending_or_frozen_batch. Renumber this branch's migrations and all their narrative references: 60 unique_pending_or_frozen_batch -> 61 61 dedupe_supply_update_events -> 62 62 backfill_supply_update_event_keys -> 63 LatestMigrationVersion bumps to 63 and the Migration62BackfillEventKeys constant becomes Migration63BackfillEventKeys.
1 parent 9ede8f1 commit 080e146

21 files changed

Lines changed: 51 additions & 51 deletions

sample-tapd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@
529529
; One-shot recovery: when set, tapd cancels all but the most recent
530530
; minting batch in BatchStatePending or BatchStateFrozen and then
531531
; exits. Used to recover a legacy database that violates the
532-
; singleton pre-broadcast batch invariant added in migration 000060
532+
; singleton pre-broadcast batch invariant added in migration 000061
533533
; (e.g. one with duplicate pending batches that blocks the
534534
; migration). Default value is false.
535535
; repair.cancel-duplicate-batches=false

tapcfg/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ type ExperimentalConfig struct {
365365
// for operator use after a constraint or invariant failure has
366366
// prevented normal startup.
367367
type RepairConfig struct {
368-
CancelDuplicateBatches bool `long:"cancel-duplicate-batches" description:"If set, tapd cancels all but the most recent minting batch in BatchStatePending or BatchStateFrozen and then exits. Used to recover from a database that violates the singleton pre-broadcast batch invariant added in migration 000060 (e.g. a legacy DB with duplicate pending batches that blocks the migration)."`
368+
CancelDuplicateBatches bool `long:"cancel-duplicate-batches" description:"If set, tapd cancels all but the most recent minting batch in BatchStatePending or BatchStateFrozen and then exits. Used to recover from a database that violates the singleton pre-broadcast batch invariant added in migration 000061 (e.g. a legacy DB with duplicate pending batches that blocks the migration)."`
369369
}
370370

371371
// CleanAndValidate performs final processing on the ExperimentalConfig,

tapcfg/repair.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import (
1414

1515
// RunRepairTool inspects the configured database for batches that
1616
// violate the singleton "≤ 1 in {Pending, Frozen}" invariant added
17-
// in migration 000060, and cancels all but the most recent. The
17+
// in migration 000061, and cancels all but the most recent. The
1818
// preserved batch is the one with the latest CreationTime; cancelled
1919
// batches transition to BatchStateSeedlingCancelled, leaving their
2020
// row and seedlings on disk for later inspection.
2121
//
2222
// The function opens the database with migrations skipped, so it can
2323
// run against a legacy database whose state would otherwise fail the
2424
// migration. After this tool exits cleanly, restarting tapd normally
25-
// will let migration 000060 succeed.
25+
// will let migration 000061 succeed.
2626
func RunRepairTool(cfg *Config, cfgLogger btclog.Logger) error {
2727
// Open the database with migrations skipped. We want to inspect
2828
// and repair a database whose state would otherwise prevent
29-
// migration 000060 from applying; running migrations as part of
29+
// migration 000061 from applying; running migrations as part of
3030
// opening the DB would defeat the purpose.
3131
var (
3232
db tapdb.DatabaseBackend
@@ -127,6 +127,6 @@ func RunRepairTool(cfg *Config, cfgLogger btclog.Logger) error {
127127

128128
cfgLogger.Infof("repair: complete; cancelled %d duplicate "+
129129
"batches, preserved 1. Restart tapd normally to let "+
130-
"migration 000060 apply.", len(preBroadcast)-1)
130+
"migration 000061 apply.", len(preBroadcast)-1)
131131
return nil
132132
}

tapdb/asset_minting_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ func TestUpdateBatchStateMemoryCoherence(t *testing.T) {
21572157
}
21582158

21592159
// TestSingletonPreBroadcastBatchConstraint exercises the partial
2160-
// unique index added in migration 000060. At most one
2160+
// unique index added in migration 000061. At most one
21612161
// asset_minting_batches row may be in BatchStatePending or
21622162
// BatchStateFrozen at any time; the second insert into that set
21632163
// must fail with a constraint error, and a row in

tapdb/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// daemon.
2525
//
2626
// NOTE: This MUST be updated when a new migration is added.
27-
LatestMigrationVersion = 62
27+
LatestMigrationVersion = 63
2828
)
2929

3030
// DatabaseBackend is an interface that contains all methods our different

tapdb/migrations_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,19 +1401,19 @@ func TestSequenceConsistency(t *testing.T) {
14011401
}
14021402
}
14031403

1404-
// TestMigration62BackfillSupplyUpdateEventKeys verifies that the
1405-
// programmatic migration at version 62 fills the event_key column for
1404+
// TestMigration63BackfillSupplyUpdateEventKeys verifies that the
1405+
// programmatic migration at version 63 fills the event_key column for
14061406
// every supply_update_events row created before the column existed.
1407-
// Migration 61 added the column nullable; rows inserted at version 61
1407+
// Migration 62 added the column nullable; rows inserted at version 62
14081408
// (or earlier) have event_key=NULL, and the dedup invariant only kicks
14091409
// in once the backfill has run.
1410-
func TestMigration62BackfillSupplyUpdateEventKeys(t *testing.T) {
1410+
func TestMigration63BackfillSupplyUpdateEventKeys(t *testing.T) {
14111411
ctx := context.Background()
14121412

1413-
// Start at version 61: the event_key column exists, the unique
1413+
// Start at version 62: the event_key column exists, the unique
14141414
// index exists (and tolerates multiple NULLs), but no rows have
14151415
// been hashed yet.
1416-
db := NewTestDBWithVersion(t, 61)
1416+
db := NewTestDBWithVersion(t, 62)
14171417

14181418
// Insert three rows with NULL event_key. update_type_id values
14191419
// match the rows seeded by migration 40 (0=mint, 1=burn,
@@ -1436,7 +1436,7 @@ func TestMigration62BackfillSupplyUpdateEventKeys(t *testing.T) {
14361436

14371437
for _, s := range seeds {
14381438
// EventKey is intentionally nil so the row mimics what a
1439-
// legacy database holds before migration 62's backfill.
1439+
// legacy database holds before migration 63's backfill.
14401440
_, err := db.InsertSupplyUpdateEvent(
14411441
ctx, sqlc.InsertSupplyUpdateEventParams{
14421442
GroupKey: groupKey,
@@ -1465,7 +1465,7 @@ func TestMigration62BackfillSupplyUpdateEventKeys(t *testing.T) {
14651465
}
14661466
require.NoError(t, preRows.Close())
14671467

1468-
// Advance to latest -- the programmatic migration at 62 runs the
1468+
// Advance to latest -- the programmatic migration at 63 runs the
14691469
// backfill.
14701470
err = db.ExecuteMigrations(TargetLatest, WithProgrammaticMigrations(
14711471
makeProgrammaticMigrations(db, programmaticMigrations, true),
@@ -1498,15 +1498,15 @@ func TestMigration62BackfillSupplyUpdateEventKeys(t *testing.T) {
14981498
require.Equal(t, len(seeds), seen)
14991499
}
15001500

1501-
// TestMigration62BackfillDedupesLegacyDuplicates simulates the legacy
1501+
// TestMigration63BackfillDedupesLegacyDuplicates simulates the legacy
15021502
// failure mode this PR closes: pre-migration databases could contain
15031503
// multiple supply_update_events rows with identical content. The
1504-
// migration 62 backfill must drop the duplicates rather than fail on
1505-
// the unique index added in migration 61.
1506-
func TestMigration62BackfillDedupesLegacyDuplicates(t *testing.T) {
1504+
// migration 63 backfill must drop the duplicates rather than fail on
1505+
// the unique index added in migration 62.
1506+
func TestMigration63BackfillDedupesLegacyDuplicates(t *testing.T) {
15071507
ctx := context.Background()
15081508

1509-
db := NewTestDBWithVersion(t, 61)
1509+
db := NewTestDBWithVersion(t, 62)
15101510

15111511
groupKey := bytes.Repeat([]byte{0x42}, 32)
15121512
payload := []byte("event-payload-duplicate")
@@ -1533,7 +1533,7 @@ func TestMigration62BackfillDedupesLegacyDuplicates(t *testing.T) {
15331533
`).Scan(&preCount))
15341534
require.Equal(t, 3, preCount)
15351535

1536-
// Run the backfill. The unique index added in migration 61
1536+
// Run the backfill. The unique index added in migration 62
15371537
// would reject the naive UPDATE for the second and third
15381538
// rows; the backfill must dedupe before writing.
15391539
err := db.ExecuteMigrations(TargetLatest, WithProgrammaticMigrations(

tapdb/programmatic_migrations.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ const (
2828
// witnesses.
2929
Migration51InsertAssetBurns = 51
3030

31-
// Migration62BackfillEventKeys is the version of the
31+
// Migration63BackfillEventKeys is the version of the
3232
// programmatic migration that computes the dedup content-hash for
3333
// every supply_update_events row that pre-dates the event_key
3434
// column. SQLite has no native SHA-256, so the work cannot be
3535
// expressed as portable SQL.
36-
Migration62BackfillEventKeys = 62
36+
Migration63BackfillEventKeys = 63
3737
)
3838

3939
// programmaticMigration is a function type for a function that performs a
@@ -48,7 +48,7 @@ var (
4848
programmaticMigrations = map[uint]programmaticMigration{
4949
Migration50ScriptKeyType: determineAndAssignScriptKeyType,
5050
Migration51InsertAssetBurns: insertAssetBurns,
51-
Migration62BackfillEventKeys: backfillSupplyUpdateEventKeys,
51+
Migration63BackfillEventKeys: backfillSupplyUpdateEventKeys,
5252
}
5353
)
5454

@@ -339,15 +339,15 @@ func insertAssetBurns(ctx context.Context, q sqlc.Querier) error {
339339

340340
// backfillSupplyUpdateEventKeys computes a content-hash for every
341341
// supply_update_events row that pre-dates the event_key column (added
342-
// in migration 000061) and stores it in the new column. After this
342+
// in migration 000062) and stores it in the new column. After this
343343
// migration runs every row holds a hash, and the unique index on
344344
// event_key enforces the no-duplicates invariant for new inserts.
345345
//
346346
// Legacy databases may already contain duplicate rows (the bug this
347347
// PR fixes -- restart re-fires of the same logical event). Two rows
348348
// with identical content hash to the same key, so the second
349349
// SetSupplyUpdateEventKey would violate the unique index added in
350-
// migration 000061. We dedupe in-memory by tracking the hashes we've
350+
// migration 000062. We dedupe in-memory by tracking the hashes we've
351351
// already assigned and dropping any row whose hash we've seen.
352352
func backfillSupplyUpdateEventKeys(ctx context.Context,
353353
q sqlc.Querier) error {
@@ -371,7 +371,7 @@ func backfillSupplyUpdateEventKeys(ctx context.Context,
371371
// A prior row in this loop already claimed this
372372
// hash, so the current row is a duplicate of an
373373
// earlier logical event. Drop it; the unique
374-
// index in migration 000061 would otherwise
374+
// index in migration 000062 would otherwise
375375
// reject the UPDATE below.
376376
log.Debugf("Dropping duplicate supply update "+
377377
"event %d during backfill", row.EventID)

tapdb/sqlc/migrations/000060_unique_pending_or_frozen_batch.down.sql renamed to tapdb/sqlc/migrations/000061_unique_pending_or_frozen_batch.down.sql

File renamed without changes.

tapdb/sqlc/migrations/000060_unique_pending_or_frozen_batch.up.sql renamed to tapdb/sqlc/migrations/000061_unique_pending_or_frozen_batch.up.sql

File renamed without changes.

tapdb/sqlc/migrations/000062_backfill_supply_update_event_keys.down.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)