@moneypot/hub 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
-- Migration: Add hash_id to hub.outcome_bet table
|
|
2
2
|
|
|
3
|
-
--
|
|
3
|
+
-- Add the hash_id column (nullable initially)
|
|
4
4
|
ALTER TABLE hub.outcome_bet
|
|
5
5
|
ADD COLUMN hash_id uuid REFERENCES hub.hash(id);
|
|
6
6
|
|
|
7
|
-
--
|
|
7
|
+
-- Index
|
|
8
8
|
CREATE INDEX outcome_bet_hash_id_idx ON hub.outcome_bet(hash_id);
|
|
9
9
|
|
|
10
|
-
--
|
|
10
|
+
-- Update existing rows to set hash_id based on hash_chain_id
|
|
11
11
|
-- This uses a window function to assign row numbers within each hash_chain_id group
|
|
12
12
|
-- ordered by the bet creation time (id)
|
|
13
13
|
WITH bet_iterations AS (
|
|
@@ -37,18 +37,18 @@ SET hash_id = hm.hash_id
|
|
|
37
37
|
FROM hash_mapping hm
|
|
38
38
|
WHERE ob.id = hm.bet_id;
|
|
39
39
|
|
|
40
|
-
--
|
|
40
|
+
-- Make hash_id NOT NULL after populating it
|
|
41
41
|
ALTER TABLE hub.outcome_bet ALTER COLUMN hash_id SET NOT NULL;
|
|
42
42
|
|
|
43
|
-
--
|
|
44
|
-
ALTER TABLE hub.outcome_bet DROP COLUMN hash_chain_id;
|
|
45
|
-
|
|
46
|
-
-- Step 5: Add client_seed column to hash table
|
|
43
|
+
-- Add client_seed column to hash table
|
|
47
44
|
ALTER TABLE hub.hash ADD COLUMN client_seed text null;
|
|
48
45
|
|
|
49
|
-
--
|
|
46
|
+
-- Update hash table with client_seed from hash_chain for each outcome_bet
|
|
50
47
|
UPDATE hub.hash h
|
|
51
48
|
SET client_seed = hc.client_seed
|
|
52
49
|
FROM hub.outcome_bet ob
|
|
53
50
|
JOIN hub.hash_chain hc ON hc.id = ob.hash_chain_id
|
|
54
|
-
WHERE h.id = ob.hash_id;
|
|
51
|
+
WHERE h.id = ob.hash_id;
|
|
52
|
+
|
|
53
|
+
-- Drop hash chain id
|
|
54
|
+
ALTER TABLE hub.outcome_bet DROP COLUMN hash_chain_id;
|