Skip to content

Commit

Permalink
db: Add an epochNo column to StakeDeregistration table
Browse files Browse the repository at this point in the history
  • Loading branch information
erikd committed Jul 29, 2021
1 parent 960a546 commit f4bf5bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Expand Up @@ -309,7 +309,7 @@ insertDelegCert
insertDelegCert tracer network txId idx epochNo slotNo dCert =
case dCert of
Shelley.RegKey cred -> insertStakeRegistration tracer txId idx $ Generic.annotateStakingCred network cred
Shelley.DeRegKey cred -> insertStakeDeregistration tracer network txId idx cred
Shelley.DeRegKey cred -> insertStakeDeregistration tracer network epochNo txId idx cred
Shelley.Delegate (Shelley.Delegation cred poolkh) -> insertDelegation tracer network txId idx epochNo slotNo cred poolkh

insertPoolRegister
Expand Down Expand Up @@ -476,14 +476,15 @@ insertStakeRegistration _tracer txId idx rewardAccount = do

insertStakeDeregistration
:: (MonadBaseControl IO m, MonadIO m)
=> Trace IO Text -> Ledger.Network -> DB.TxId -> Word16 -> Ledger.StakeCredential StandardCrypto
=> Trace IO Text -> Ledger.Network -> EpochNo -> DB.TxId -> Word16 -> Ledger.StakeCredential StandardCrypto
-> ExceptT SyncNodeError (ReaderT SqlBackend m) ()
insertStakeDeregistration _tracer network txId idx cred = do
insertStakeDeregistration _tracer network (EpochNo epochNo) txId idx cred = do
scId <- liftLookupFail "insertStakeDeregistration" $ queryStakeAddress (Generic.stakingCredHash network cred)
void . lift . DB.insertStakeDeregistration $
DB.StakeDeregistration
{ DB.stakeDeregistrationAddrId = scId
, DB.stakeDeregistrationCertIndex = idx
, DB.stakeDeregistrationEpochNo = epochNo
, DB.stakeDeregistrationTxId = txId
}

Expand Down
1 change: 1 addition & 0 deletions cardano-db/src/Cardano/Db/Schema.hs
Expand Up @@ -254,6 +254,7 @@ share
StakeDeregistration
addrId StakeAddressId OnDeleteCascade
certIndex Word16
epochNo Word64 sqltype=uinteger
txId TxId OnDeleteCascade
UniqueStakeDeregistration addrId txId

Expand Down
19 changes: 19 additions & 0 deletions schema/migration-2-0014-20210729.sql
@@ -0,0 +1,19 @@
-- Persistent generated migration.

CREATE FUNCTION migrate() RETURNS void AS $$
DECLARE
next_version int ;
BEGIN
SELECT stage_two + 1 INTO next_version FROM schema_version ;
IF next_version = 14 THEN
EXECUTE 'ALTER TABLE "stake_deregistration" ADD COLUMN "epoch_no" uinteger NOT NULL' ;
-- Hand written SQL statements can be added here.
UPDATE schema_version SET stage_two = next_version ;
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
END IF ;
END ;
$$ LANGUAGE plpgsql ;

SELECT migrate() ;

DROP FUNCTION migrate() ;

0 comments on commit f4bf5bf

Please sign in to comment.