Skip to content

Commit d9a8771

Browse files
committed
Remove Unique Key from metadata
Fixes #1714
1 parent 71b4562 commit d9a8771

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/PoolAndSmash.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ poolDeRegMany =
194194

195195
assertBlockNoBackoff dbSync 3
196196
-- TODO fix PoolOwner and PoolRelay unique key
197-
assertPoolCounters dbSync (addPoolCounters (1, 1, 5, 10, 3, 5) initCounter)
197+
assertPoolCounters dbSync (addPoolCounters (1, 5, 5, 10, 3, 5) initCounter)
198198

199199
st <- getAlonzoLedgerState interpreter
200200
-- Not retired yet, because epoch has not changed
@@ -205,7 +205,7 @@ poolDeRegMany =
205205

206206
assertBlockNoBackoff dbSync (fromIntegral $ length a + 3)
207207
-- these counters are the same
208-
assertPoolCounters dbSync (addPoolCounters (1, 1, 5, 10, 3, 5) initCounter)
208+
assertPoolCounters dbSync (addPoolCounters (1, 5, 5, 10, 3, 5) initCounter)
209209

210210
-- from all these certificates only the latest matters. So it will retire
211211
-- on epoch 0

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Other.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ poolDeRegMany =
267267

268268
assertBlockNoBackoff dbSync 3
269269
-- TODO fix PoolOwner and PoolRelay unique key
270-
assertPoolCounters dbSync (addPoolCounters (1, 1, 5, 10, 3, 5) initCounter)
270+
assertPoolCounters dbSync (addPoolCounters (1, 5, 5, 10, 3, 5) initCounter)
271271

272272
st <- getBabbageLedgerState interpreter
273273
-- Not retired yet, because epoch has not changed
@@ -278,7 +278,7 @@ poolDeRegMany =
278278

279279
assertBlockNoBackoff dbSync (fromIntegral $ length a + 3)
280280
-- these counters are the same
281-
assertPoolCounters dbSync (addPoolCounters (1, 1, 5, 10, 3, 5) initCounter)
281+
assertPoolCounters dbSync (addPoolCounters (1, 5, 5, 10, 3, 5) initCounter)
282282

283283
-- from all these certificates only the latest matters. So it will retire
284284
-- on epoch 0

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Other.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ poolDeRegMany =
294294
-- Verify pool counts
295295
-- (poolHashes, poolMetadataRefs, poolUpdates, poolOwners, poolRetires, poolRelays)
296296
-- TODO fix PoolOwner and PoolRelay unique key
297-
assertPoolCounters dbSync (addPoolCounters (1, 1, 4, 8, 3, 4) initCounter)
297+
assertPoolCounters dbSync (addPoolCounters (1, 4, 4, 8, 3, 4) initCounter)
298298

299299
state' <- Api.getConwayLedgerState interpreter
300300
-- Not retired yet, because epoch hasn't changed
@@ -309,7 +309,7 @@ poolDeRegMany =
309309
-- Wait for it to sync
310310
assertBlockNoBackoff dbSync (length blks + 3)
311311
-- Pool counts should not have changed
312-
assertPoolCounters dbSync (addPoolCounters (1, 1, 4, 8, 3, 4) initCounter)
312+
assertPoolCounters dbSync (addPoolCounters (1, 4, 4, 8, 3, 4) initCounter)
313313
-- Only the latest certificate matters, so it should be retired in epoch 0
314314
assertPoolLayerCounters
315315
dbSync

cardano-db/src/Cardano/Db/Insert.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ insertPoolHash :: (MonadBaseControl IO m, MonadIO m) => PoolHash -> ReaderT SqlB
253253
insertPoolHash = insertCheckUnique "PoolHash"
254254

255255
insertPoolMetadataRef :: (MonadBaseControl IO m, MonadIO m) => PoolMetadataRef -> ReaderT SqlBackend m PoolMetadataRefId
256-
insertPoolMetadataRef = insertCheckUnique "PoolMetadataRef"
256+
insertPoolMetadataRef = insertUnchecked "PoolMetadataRef"
257257

258258
insertPoolOwner :: (MonadBaseControl IO m, MonadIO m) => PoolOwner -> ReaderT SqlBackend m PoolOwnerId
259259
insertPoolOwner = insertUnchecked "PoolOwner"

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ share
237237
url PoolUrl sqltype=varchar
238238
hash ByteString sqltype=hash32type
239239
registeredTxId TxId noreference -- Only used for rollback.
240-
UniquePoolMetadataRef poolId url hash
241240

242241
PoolUpdate
243242
hashId PoolHashId noreference
@@ -297,7 +296,7 @@ share
297296

298297
TxMetadata
299298
key DbWord64 sqltype=word64type
300-
json Text Maybe
299+
json Text Maybe sqltype=jsonb
301300
bytes ByteString sqltype=bytea
302301
txId TxId noreference
303302

@@ -407,22 +406,22 @@ share
407406
txId TxId noreference
408407
hash ByteString sqltype=hash28type
409408
type ScriptType sqltype=scripttype
410-
json Text Maybe
409+
json Text Maybe sqltype=jsonb
411410
bytes ByteString Maybe sqltype=bytea
412411
serialisedSize Word64 Maybe sqltype=word31type
413412
UniqueScript hash
414413

415414
Datum
416415
hash ByteString sqltype=hash32type
417416
txId TxId noreference
418-
value Text Maybe
417+
value Text Maybe sqltype=jsonb
419418
bytes ByteString sqltype=bytea
420419
UniqueDatum hash
421420

422421
RedeemerData
423422
hash ByteString sqltype=hash32type
424423
txId TxId noreference
425-
value Text Maybe
424+
value Text Maybe sqltype=jsonb
426425
bytes ByteString sqltype=bytea
427426
UniqueRedeemerData hash
428427

@@ -553,7 +552,7 @@ share
553552

554553
CostModel
555554
hash ByteString sqltype=hash32type
556-
costs Text
555+
costs Text sqltype=jsonb
557556
UniqueCostModel hash
558557

559558
ExtraMigrations
@@ -613,7 +612,7 @@ share
613612
expiration Word64 Maybe sqltype=word31type
614613
votingAnchorId VotingAnchorId Maybe noreference
615614
type GovActionType sqltype=govactiontype
616-
description Text
615+
description Text sqltype=jsonb
617616
paramProposal ParamProposalId Maybe noreference
618617
ratifiedEpoch Word64 Maybe sqltype=word31type
619618
enactedEpoch Word64 Maybe sqltype=word31type
@@ -671,7 +670,7 @@ share
671670
poolId PoolHashId noreference
672671
tickerName Text
673672
hash ByteString sqltype=hash32type
674-
json Text
673+
json Text sqltype=jsonb
675674
bytes ByteString sqltype=bytea
676675
pmrId PoolMetadataRefId noreference
677676
UniqueOffChainPoolData poolId hash
@@ -694,7 +693,7 @@ share
694693
hash ByteString
695694
language Text
696695
comment Text Maybe
697-
json Text
696+
json Text sqltype=jsonb
698697
bytes ByteString sqltype=bytea
699698
warning Text Maybe
700699
isValid Bool Maybe

schema/migration-2-0034-20240301.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ BEGIN
1111
EXECUTE 'ALTER TABLE "pool_update" ADD COLUMN "deposit" lovelace NULL' ;
1212
EXECUTE 'ALTER TABLE "stake_registration" ADD COLUMN "deposit" lovelace NULL' ;
1313
EXECUTE 'ALTER TABLE "ada_pots" RENAME COLUMN "deposits" TO "deposits_stake"';
14-
EXECUTE 'ALTER TABLE "ada_pots" ADD COLUMN "deposits_drep" lovelace NOT NULL' ;
15-
EXECUTE 'ALTER TABLE "ada_pots" ADD COLUMN "deposits_proposal" lovelace NOT NULL';
14+
EXECUTE 'ALTER TABLE "ada_pots" ADD COLUMN "deposits_drep" lovelace NOT NULL DEFAULT 0' ;
15+
EXECUTE 'ALTER TABLE "ada_pots" ADD COLUMN "deposits_proposal" lovelace NOT NULL DEFAULT 0';
1616
EXECUTE 'ALTER TABLE "instant_reward" RENAME TO "reward_rest"';
1717
EXECUTE 'ALTER TABLE "reward_rest" RENAME CONSTRAINT "unique_instant_reward" TO "unique_reward_rest"';
1818
EXECUTE 'ALTER TABLE "param_proposal" ADD COLUMN "min_fee_ref_script_cost_per_byte" DOUBLE PRECISION NULL' ;

schema/migration-2-0039-20240703.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Persistent generated migration.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
DECLARE
5+
next_version int ;
6+
BEGIN
7+
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8+
IF next_version = 39 THEN
9+
EXECUTE 'ALTER TABLE "ada_pots" ALTER COLUMN "deposits_drep" DROP DEFAULT' ;
10+
EXECUTE 'ALTER TABLE "ada_pots" ALTER COLUMN "deposits_proposal" DROP DEFAULT' ;
11+
EXECUTE 'ALTER TABLE "pool_metadata_ref" DROP CONSTRAINT "unique_pool_metadata_ref"' ;
12+
-- Hand written SQL statements can be added here.
13+
UPDATE schema_version SET stage_two = next_version ;
14+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
15+
END IF ;
16+
END ;
17+
$$ LANGUAGE plpgsql ;
18+
19+
SELECT migrate() ;
20+
21+
DROP FUNCTION migrate() ;

0 commit comments

Comments
 (0)