|
| 1 | +{-# LANGUAGE ExistentialQuantification #-} |
| 2 | +{-# LANGUAGE OverloadedStrings, DataKinds, FlexibleInstances #-} |
| 3 | +{-# LANGUAGE QuasiQuotes #-} |
| 4 | +{-# LANGUAGE MultiParamTypeClasses #-} |
| 5 | +{-# LANGUAGE TemplateHaskell #-} |
| 6 | +{-# LANGUAGE TypeFamilies #-} |
| 7 | +{-# LANGUAGE UndecidableInstances #-} |
| 8 | +{-# LANGUAGE StandaloneDeriving #-} |
| 9 | +{-# LANGUAGE DerivingStrategies #-} |
| 10 | +{-# LANGUAGE GeneralizedNewtypeDeriving #-} |
| 11 | +{-# OPTIONS_GHC -Wno-unused-top-binds #-} |
| 12 | + |
| 13 | +module MigrationReferenceSpec where |
| 14 | + |
| 15 | +import PgInit |
| 16 | + |
| 17 | +import Control.Monad.Trans.Writer (censor, mapWriterT) |
| 18 | +import Data.Text (Text, isInfixOf) |
| 19 | + |
| 20 | +share [mkPersist sqlSettings, mkMigrate "referenceMigrate"] [persistLowerCase| |
| 21 | + |
| 22 | +LocationCapabilities |
| 23 | + Id Text |
| 24 | + bio Text |
| 25 | + |
| 26 | +LocationCapabilitiesPrintingProcess |
| 27 | + locationCapabilitiesId LocationCapabilitiesId |
| 28 | + |
| 29 | +LocationCapabilitiesPrintingFinish |
| 30 | + locationCapabilitiesId LocationCapabilitiesId |
| 31 | + |
| 32 | +LocationCapabilitiesSubstrate |
| 33 | + locationCapabilitiesId LocationCapabilitiesId |
| 34 | + |
| 35 | +|] |
| 36 | + |
| 37 | +spec :: Spec |
| 38 | +spec = describe "MigrationReferenceSpec" $ do |
| 39 | + it "works" $ runConnAssert $ do |
| 40 | + let |
| 41 | + noForeignKeys :: CautiousMigration -> CautiousMigration |
| 42 | + noForeignKeys = filter ((not . isReference) . snd) |
| 43 | + |
| 44 | + onlyForeignKeys :: CautiousMigration -> CautiousMigration |
| 45 | + onlyForeignKeys = filter (isReference . snd) |
| 46 | + |
| 47 | + isReference :: Text -> Bool |
| 48 | + isReference migration = "REFERENCES" `isInfixOf` migration |
| 49 | + |
| 50 | + runMigration |
| 51 | + $ mapWriterT (censor noForeignKeys) |
| 52 | + $ referenceMigrate |
| 53 | + |
| 54 | + runMigration |
| 55 | + $ mapWriterT (censor onlyForeignKeys) |
| 56 | + $ referenceMigrate |
0 commit comments