hpqtypes-extras 1.9.0.0 → 1.9.0.1
raw patch · 3 files changed
+26/−13 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +3/−0
- hpqtypes-extras.cabal +3/−3
- src/Database/PostgreSQL/PQTypes/Checks.hs +20/−10
CHANGELOG.md view
@@ -1,3 +1,6 @@+# hpqtypes-extras-1.9.0.1 (2019-06-04)+* Create composite types automatically only if database is empty.+ # hpqtypes-extras-1.9.0.0 (2019-05-22) * Extend `checkDatabaseAllowUnknownTables` to allow unknown composite types and rename it to `checkDatabaseAllowUnknownObjects`
hpqtypes-extras.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: hpqtypes-extras-version: 1.9.0.0+version: 1.9.0.1 synopsis: Extra utilities for hpqtypes library description: The following extras for hpqtypes library: .@@ -63,8 +63,8 @@ , lifted-base >= 0.2 && < 0.3 , monad-control >= 1.0 && < 1.1 , semigroups >= 0.16 && < 0.20- , text-show >= 3.8 && < 3.9- , log-base >= 0.8 && < 0.9+ , text-show >= 3.7 && < 3.9+ , log-base >= 0.7 && < 0.9 , safe >= 0.3 && < 0.4 default-language: Haskell2010
src/Database/PostgreSQL/PQTypes/Checks.hs view
@@ -65,7 +65,8 @@ tablesWithVersions <- getTableVersions (tableVersions : tables) -- 'checkDBConsistency' also performs migrations. checkDBConsistency options domains tablesWithVersions migrations- resultCheck =<< checkCompositesStructure CreateCompositesIfDatabaseEmpty+ resultCheck =<< checkCompositesStructure tablesWithVersions+ CreateCompositesIfDatabaseEmpty DontAllowUnknownObjects composites resultCheck =<< checkDomainsStructure domains@@ -105,7 +106,7 @@ checkDatabase_ options ovm composites domains tables = do tablesWithVersions <- getTableVersions (tableVersions : tables) resultCheck $ checkVersions tablesWithVersions- resultCheck =<< checkCompositesStructure DontCreateComposites ovm composites+ resultCheck =<< checkCompositesStructure tablesWithVersions DontCreateComposites ovm composites resultCheck =<< checkDomainsStructure domains resultCheck =<< checkDBStructure options tablesWithVersions when (ovm == DontAllowUnknownObjects) $ do@@ -117,7 +118,7 @@ resultCheck =<< checkInitialSetups tables where- checkVersions :: [(Table, Int32)] -> ValidationResult+ checkVersions :: TablesWithVersions -> ValidationResult checkVersions vs = mconcat . map checkVersion $ vs checkVersion :: (Table, Int32) -> ValidationResult@@ -327,12 +328,14 @@ -- database and the list of their code definitions. checkCompositesStructure :: MonadDB m- => CompositesCreationMode+ => TablesWithVersions+ -> CompositesCreationMode -> ObjectsValidationMode -> [CompositeType] -> m ValidationResult-checkCompositesStructure ccm ovm compositeList = getDBCompositeTypes >>= \case- [] | ccm == CreateCompositesIfDatabaseEmpty -> do+checkCompositesStructure tablesWithVersions ccm ovm compositeList = getDBCompositeTypes >>= \case+ [] | noTablesPresent tablesWithVersions && ccm == CreateCompositesIfDatabaseEmpty -> do+ -- DB is not initialized, create composites if there are any defined. mapM_ (runQuery_ . sqlCreateComposite) compositeList return mempty dbCompositeTypes -> pure $ mconcat@@ -390,7 +393,7 @@ checkDBStructure :: forall m. (MonadDB m, MonadThrow m) => ExtrasOptions- -> [(Table, Int32)]+ -> TablesWithVersions -> m ValidationResult checkDBStructure options tables = fmap mconcat . forM tables $ \(table, version) ->@@ -551,7 +554,7 @@ -- the 'tables' list checkDBConsistency :: forall m. (MonadDB m, MonadLog m, MonadMask m)- => ExtrasOptions -> [Domain] -> [(Table, Int32)] -> [Migration m]+ => ExtrasOptions -> [Domain] -> TablesWithVersions -> [Migration m] -> m () checkDBConsistency options domains tablesWithVersions migrations = do autoTransaction <- tsAutoTransaction <$> getTransactionSettings@@ -564,7 +567,7 @@ -- Load version numbers of the tables that actually exist in the DB. dbTablesWithVersions <- getDBTableVersions - if all ((==) 0 . snd) tablesWithVersions+ if noTablesPresent tablesWithVersions -- No tables are present, create everything from scratch. then do@@ -917,14 +920,21 @@ $ object [ "tables" .= map unRawSQL tnms ] errorInvalidMigrations tnms +-- | Type synonym for a list of tables along with their database versions.+type TablesWithVersions = [(Table, Int32)] -- | Associate each table in the list with its version as it exists in -- the DB, or 0 if it's missing from the DB.-getTableVersions :: (MonadDB m, MonadThrow m) => [Table] -> m [(Table, Int32)]+getTableVersions :: (MonadDB m, MonadThrow m) => [Table] -> m TablesWithVersions getTableVersions tbls = sequence [ (\mver -> (tbl, fromMaybe 0 mver)) <$> checkTableVersion (tblNameString tbl) | tbl <- tbls ]++-- | Given a result of 'getTableVersions' check if no tables are present in the+-- database.+noTablesPresent :: TablesWithVersions -> Bool+noTablesPresent = all ((==) 0 . snd) -- | Like 'getTableVersions', but for all user-defined tables that -- actually exist in the DB.