Skip to content

Commit 979cbb7

Browse files
committed
Run the migration on this iteration.
1 parent 932b2d1 commit 979cbb7

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

sql/2025-02-25_causal_depth_migration.sql renamed to sql/migration-helpers/2025-02-25_causal_depth_migration.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ INSERT INTO unfinished_component_depths (id)
4343
SELECT FROM component_depth cd WHERE cd.component_hash_id = ch.id
4444
);
4545

46+
-- Afterwards
47+
DROP TABLE unfinished_causal_depths;
48+
DROP TABLE unfinished_namespace_depths;
49+
DROP TABLE unfinished_patch_depths;
50+
DROP TABLE unfinished_component_depths;

src/Share/Web/UCM/SyncV2/Impl.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ batchSize :: Int32
4848
batchSize = 1000
4949

5050
streamSettings :: Hash32 -> Maybe SyncV2.BranchRef -> StreamInitInfo
51-
streamSettings rootCausalHash rootBranchRef = StreamInitInfo {version = SyncV2.Version 1, entitySorting = SyncV2.DependenciesFirst, numEntities = Nothing, rootCausalHash, rootBranchRef}
51+
streamSettings rootCausalHash rootBranchRef = StreamInitInfo {version = SyncV2.Version 1, entitySorting = SyncV2.Unsorted, numEntities = Nothing, rootCausalHash, rootBranchRef}
5252

5353
server :: Maybe UserId -> SyncV2.Routes WebAppServer
5454
server mayUserId =

src/Share/Web/UCM/SyncV2/Queries.hs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ allSerializedDependenciesOfCausalCursor cid exceptCausalHashes = do
5050
JOIN component_hashes ch ON dh.hash = ch.base32
5151
|]
5252
cursor <-
53-
PGCursor.newRowCursor
53+
PGCursor.newRowCursor @(CBORBytes TempEntity, Hash32, Maybe Int32)
5454
"serialized_entities"
5555
[sql|
5656
WITH RECURSIVE transitive_causals(causal_id, causal_hash, causal_namespace_hash_id) AS (
@@ -178,32 +178,44 @@ allSerializedDependenciesOfCausalCursor cid exceptCausalHashes = do
178178
JOIN serialized_components sc ON sc.user_id = #{ownerUserId} AND tc.component_hash_id = sc.component_hash_id
179179
JOIN bytes ON sc.bytes_id = bytes.id
180180
JOIN component_hashes ch ON tc.component_hash_id = ch.id
181-
JOIN component_depth cd ON ch.id = cd.component_hash_id
181+
LEFT JOIN component_depth cd ON ch.id = cd.component_hash_id
182182
)
183183
UNION ALL
184184
(SELECT bytes.bytes, ap.patch_hash, pd.depth
185185
FROM all_patches ap
186186
JOIN serialized_patches sp ON ap.patch_id = sp.patch_id
187187
JOIN bytes ON sp.bytes_id = bytes.id
188-
JOIN patch_depth pd ON ap.patch_id = pd.patch_id
188+
LEFT JOIN patch_depth pd ON ap.patch_id = pd.patch_id
189189
)
190190
UNION ALL
191191
(SELECT bytes.bytes, an.namespace_hash, nd.depth
192192
FROM all_namespaces an
193193
JOIN serialized_namespaces sn ON an.namespace_hash_id = sn.namespace_hash_id
194194
JOIN bytes ON sn.bytes_id = bytes.id
195-
JOIN namespace_depth nd ON an.namespace_hash_id = nd.namespace_hash_id
195+
LEFT JOIN namespace_depth nd ON an.namespace_hash_id = nd.namespace_hash_id
196196
)
197197
UNION ALL
198198
(SELECT bytes.bytes, tc.causal_hash, cd.depth
199199
FROM transitive_causals tc
200200
JOIN serialized_causals sc ON tc.causal_id = sc.causal_id
201201
JOIN bytes ON sc.bytes_id = bytes.id
202-
JOIN causal_depth cd ON tc.causal_id = cd.causal_id
202+
LEFT JOIN causal_depth cd ON tc.causal_id = cd.causal_id
203203
)
204-
ORDER BY depth ASC
204+
-- Re-add this once the migration is done.
205+
-- Put them in dependency order, nulls come first because we want to bail and
206+
-- report an error
207+
-- if we somehow are missing a depth.
208+
-- ORDER BY depth ASC NULLS FIRST
205209
|]
206-
pure cursor
210+
-- pure
211+
-- ( cursor <&> \(bytes, hash, depth) -> case depth of
212+
-- -- This should never happen, but is a sanity check in case we're missing a depth.
213+
-- -- Better than silently omitting a required result.
214+
-- Nothing -> error $ "allSerializedDependenciesOfCausalCursor: Missing depth for entity: " <> show hash
215+
-- Just _ -> (bytes, hash)
216+
-- )
217+
pure
218+
(cursor <&> \(bytes, hash, _depth) -> (bytes, hash))
207219

208220
spineAndLibDependenciesOfCausalCursor :: CausalId -> CodebaseM e (PGCursor (Hash32, IsCausalSpine, IsLibRoot))
209221
spineAndLibDependenciesOfCausalCursor cid = do

0 commit comments

Comments
 (0)