File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
cardano-db/src/Cardano/Db/Operations Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ deleteUsingEpochNo epochN = do
127127 [ onlyDelete " Epoch" [EpochNo ==. epochN]
128128 , onlyDelete " DrepDistr" [DrepDistrEpochNo >. epochN]
129129 , onlyDelete " RewardRest" [RewardRestSpendableEpoch >. epochN]
130- , onlyDelete " PoolStat" [PoolStatEpochNo >= . epochN]
130+ , onlyDelete " PoolStat" [PoolStatEpochNo >. epochN]
131131 ]
132132 nullLogs <- do
133133 a <- setNullEnacted epochN
Original file line number Diff line number Diff line change 1+ CREATE FUNCTION migrate () RETURNS void AS $$
2+ DECLARE
3+ next_version int ;
4+ BEGIN
5+ SELECT stage_two + 1 INTO next_version FROM schema_version ;
6+ IF next_version = 45 THEN
7+
8+ -- Remove duplicates first
9+ DELETE FROM pool_stat
10+ WHERE id NOT IN (
11+ SELECT DISTINCT ON (pool_hash_id, epoch_no) id
12+ FROM pool_stat
13+ ORDER BY pool_hash_id, epoch_no, id
14+ );
15+
16+ -- Then add constraint if it doesn't exist
17+ DO $$
18+ BEGIN
19+ IF NOT EXISTS (
20+ SELECT 1 FROM pg_constraint
21+ WHERE conname = ' unique_pool_stat_epoch'
22+ ) THEN
23+ ALTER TABLE " pool_stat" ADD CONSTRAINT " unique_pool_stat_epoch"
24+ UNIQUE (" pool_hash_id" , " epoch_no" );
25+ END IF;
26+ END $$;
27+
28+ UPDATE schema_version SET stage_two = next_version ;
29+ RAISE NOTICE ' DB has been migrated to stage_two version %' , next_version ;
30+ END IF ;
31+ END ;
32+ $$ LANGUAGE plpgsql ;
33+
34+ SELECT migrate() ;
35+ DROP FUNCTION migrate() ;
You can’t perform that action at this time.
0 commit comments