on master help sign in
Check for HEAD in the graph
commit44ed1230f55749e2f4ab84d500135376b36ebf89 authorSridhar Ratnakumar <srid@srid.ca> dateFri 22 Jun 2018, 14:48 (8 years ago) parenta383033
4 files changed+19−4
lib/command/src/Obelisk/Command/Upgrade.hs+7−3 lib/migration/src/Obelisk/Migration.hs+12−1 migration/375acf7f2a3b3c487da2a6b30735d74d-3b614d291e262d0f281b54ff42a6bb66/obelisk-handoff migration/375acf7f2a3b3c487da2a6b30735d74d-3b614d291e262d0f281b54ff42a6bb66/obelisk-upgrade
lib/command/src/Obelisk/Command/Upgrade.hs+7−3
@@ -187,8 +187,12 @@ computeVertexHash = getDirectoryHash [migrationDirName]
187187-- | Verify the integrity of the migration graph in relation to the Git repo.
188188verifyGraph :: MonadObelisk m => FilePath -> m ()
189189verifyGraph obDir = do
190− upgradeGraph <- getMigrationGraph @Text obDir MigrationGraph_ObeliskUpgrade
191− ensureGraphIntegrity upgradeGraph
190+ upgradeGraph <- withSpinner "Reading graph" $
191+ getMigrationGraph @Text obDir MigrationGraph_ObeliskUpgrade
192+ withSpinner "Checking graph integrity" $
193+ ensureGraphIntegrity upgradeGraph
194+ withSpinner "Checking existence of HEAD vertex" $
195+ void $ getHeadVertex obDir -- HEAD vertex must be present.
192196
193197createMigrationEdgeFromHEAD :: MonadObelisk m => FilePath -> m ()
194198createMigrationEdgeFromHEAD obDir = do
@@ -215,7 +219,7 @@ getHeadVertex obDir = do
215219 [headHash] <- getHashAtGitRevision ["HEAD"] migrationIgnore obDir
216220 unless (hasVertex headHash projectGraph) $ do
217221 -- This means that the HEAD commit has no vertex in the graph,
218− -- possible due to developer negligence when commiting it.
222+ -- possibly due to developer negligence when commiting it.
219223 -- Perhaps we should use a post-commit hook or some such thing
220224 -- to reject such commits in the first place? For now, just
221225 -- error out.
lib/migration/src/Obelisk/Migration.hs+12−1
@@ -89,11 +89,16 @@ readGraph root name = doesDirectoryExist root >>= \case
8989 False -> do
9090 return Nothing
9191
92−-- | Ensures that the migration class is correct
92+-- | Ensures that the migration graph is correct
93+--
94+-- In a correct migration graph: for all pairs of nodes, all paths between
95+-- those nodes have the same migration value
9396--
9497-- Throw the following if integrity check fails
9598-- * `CyclicGraphError`
9699-- * `NonEquivalentPaths`
100+--
101+-- Complexity: O(V+E)
97102ensureGraphIntegrity
98103 :: (MonadThrow m, Monoid action, Ord action)
99104 => Migration action -> m ()
@@ -111,12 +116,18 @@ ensureGraphIntegrity m = do
111116 then pure visited
112117 else throwM $ NonEquivalentPaths start adj
113118 traverseFrom visited' acc' adj
119+ -- We only check all paths from the _first_ vertex; it is not necessary to
120+ -- check all paths between _all_ pairs of vertices as that can be proved by
121+ -- induction, as long as there is exactly one first vertex (which we check on
122+ -- further above).
114123 traverseFrom mempty mempty firstVertex
115124
116125-- | Find the concataneted actions between two vertices
117126--
118127-- All paths between the vertices must have the same mappend'ed action;
119128-- otherwise this will throw.
129+--
130+-- Complexity: O(V+E)
120131findPathAction
121132 :: (MonadThrow m, Action action, Monoid action, Ord action)
122133 => Migration action -> Hash -> Hash -> m (Maybe action)
migration/375acf7f2a3b3c487da2a6b30735d74d-3b614d291e262d0f281b54ff42a6bb66/obelisk-handoffnew file

No changes to the content.

migration/375acf7f2a3b3c487da2a6b30735d74d-3b614d291e262d0f281b54ff42a6bb66/obelisk-upgradenew file

No changes to the content.