chore(health): migration for health defaults

This commit is contained in:
Steffen Jost 2024-02-12 18:30:07 +01:00
parent 42695cf5ef
commit 192c733749

View File

@ -49,6 +49,7 @@ import qualified Data.Time.Zones as TZ
data ManualMigration
= Migration20230524QualificationUserBlock
| Migration20230703LmsUserStatus
| Migration20240212InitInterfaceHealth -- create table interface_health and fill with default values
deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic)
deriving anyclass (Universe, Finite)
@ -123,14 +124,6 @@ migrateAlwaysSafe = do
let itemDay = Map.findWithDefault today item changelogItemDays
return [st|('#{toPathPiece item}', '#{iso8601Show itemDay}')|]
in sql
-- unless (tableExists "interface_health") $ do
-- [executeQQ|
-- INSERT INTO "interface_health" ("interface", "subtype", "write", "hours")
-- VALUES
-- ('Printer', 'Acknowledge', True, 168)
-- , ('AVS' , 'Synch' , True , 96)
-- ON CONFLICT DO NOTHING;
-- |]
{-
Confusion about quotes, from the PostgreSQL Manual:
@ -185,6 +178,25 @@ customMigrations = mapF $ \case
;
|]
Migration20240212InitInterfaceHealth ->
unlessM (tableExists "interface_health") $ do -- fill health table with some defaults
[executeQQ|
CREATE TABLE "interface_health"
( id BIGSERIAL NOT NULL
, interface CHARACTER VARYING NOT NULL
, subtype CHARACTER VARYING
, write BOOLEAN
, hours BIGINT NOT NULL
, PRIMARY KEY(id)
, CONSTRAINT unique_interface_health UNIQUE(interface, subtype, write)
);
INSERT INTO "interface_health" ("interface", "subtype", "write", "hours")
VALUES
('Printer', 'Acknowledge', True, 168)
, ('AVS' , 'Synch' , True , 96)
ON CONFLICT DO NOTHING;
|]
tableExists :: MonadIO m => Text -> ReaderT SqlBackend m Bool
tableExists table = do