arbiter-migrations-0.1.0.0: SQL schema migrations for arbiter
Safe HaskellNone
LanguageGHC2024

Arbiter.Migrations

Description

Versioned, tracked migrations for job queue schemas.

Uses the postgresql-migration library to:

  • Track which migrations have been run in a database table
  • Run migrations in order
  • Prevent re-running completed migrations
  • Support incremental schema changes

The migration history is stored in a schema_name.schema_migrations table. For example, if you use the schema name "arbiter", the migration tracking table will be created at arbiter.schema_migrations.

Synopsis

Configuration

data MigrationConfig Source #

Configuration for job queue migrations

Controls which optional features are enabled when creating job queue tables.

Constructors

MigrationConfig 

Fields

  • enableNotifications :: Bool

    Whether to create LISTEN/NOTIFY triggers for reactive job claiming. When enabled, workers can subscribe to notifications instead of polling. Default: True

  • enableEventStreaming :: Bool

    Whether to create event streaming triggers for the admin UI. When enabled, every INSERT/UPDATE/DELETE on job tables fires an enriched JSON event via pg_notify on the arbiter_job_events channel. This adds overhead to every row operation — disable for maximum throughput. Default: False

defaultMigrationConfig :: MigrationConfig Source #

Default migration configuration

Tracked Migrations

runMigrationsForRegistry Source #

Arguments

:: forall (registry :: JobPayloadRegistry). RegistryTables registry 
=> Proxy registry

Proxy for the job payload registry

-> ByteString

Database connection string

-> Text

PostgreSQL schema name (e.g., "arbiter")

-> MigrationConfig

Migration configuration

-> IO (MigrationResult String)

Migration results

Run migrations for all tables in a queue registry

This function creates all tables defined in the type-level registry within a single PostgreSQL schema. Each payload type gets its own table pair (main + DLQ) within the schema.

Note: This function creates the schema first (outside of migration tracking) so that the schema_migrations table can be placed inside the same schema.

PostgreSQL notices (like "NOTICE: relation already exists") are suppressed during migration to reduce log noise.

Example:

type AppRegistry =
  '[ '("email_jobs", EmailPayload)
   , '("order_jobs", OrderPayload)
   ]

main :: IO ()
main = do
  result <- runMigrationsForRegistry
              (Proxy @AppRegistry)
              "host=localhost dbname=mydb"
              "arbiter"
              defaultMigrationConfig

runMigrationsTrackedForTables Source #

Arguments

:: ByteString

Database connection string

-> Text

Schema name

-> [Text]

List of table names to create

-> MigrationConfig

Migration configuration

-> IO (MigrationResult String) 

Run migrations for multiple tables within a single schema.

jobQueueMigrationsForTable Source #

Arguments

:: Text

Schema name

-> Text

Table name

-> MigrationConfig

Migration configuration

-> [MigrationCommand]

List of migration commands

All job queue migrations for a single table

This creates migrations for one table and its DLQ within a schema. Each table gets its own set of migrations with unique version identifiers.

Re-exports

data MigrationResult a #

Instances

Instances details
Functor MigrationResult 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Methods

fmap :: (a -> b) -> MigrationResult a -> MigrationResult b #

(<$) :: a -> MigrationResult b -> MigrationResult a #

Foldable MigrationResult 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Methods

fold :: Monoid m => MigrationResult m -> m #

foldMap :: Monoid m => (a -> m) -> MigrationResult a -> m #

foldMap' :: Monoid m => (a -> m) -> MigrationResult a -> m #

foldr :: (a -> b -> b) -> b -> MigrationResult a -> b #

foldr' :: (a -> b -> b) -> b -> MigrationResult a -> b #

foldl :: (b -> a -> b) -> b -> MigrationResult a -> b #

foldl' :: (b -> a -> b) -> b -> MigrationResult a -> b #

foldr1 :: (a -> a -> a) -> MigrationResult a -> a #

foldl1 :: (a -> a -> a) -> MigrationResult a -> a #

toList :: MigrationResult a -> [a] #

null :: MigrationResult a -> Bool #

length :: MigrationResult a -> Int #

elem :: Eq a => a -> MigrationResult a -> Bool #

maximum :: Ord a => MigrationResult a -> a #

minimum :: Ord a => MigrationResult a -> a #

sum :: Num a => MigrationResult a -> a #

product :: Num a => MigrationResult a -> a #

Traversable MigrationResult 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Methods

traverse :: Applicative f => (a -> f b) -> MigrationResult a -> f (MigrationResult b) #

sequenceA :: Applicative f => MigrationResult (f a) -> f (MigrationResult a) #

mapM :: Monad m => (a -> m b) -> MigrationResult a -> m (MigrationResult b) #

sequence :: Monad m => MigrationResult (m a) -> m (MigrationResult a) #

Read a => Read (MigrationResult a) 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Show a => Show (MigrationResult a) 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Eq a => Eq (MigrationResult a) 
Instance details

Defined in Database.PostgreSQL.Simple.Migration

Ord a => Ord (MigrationResult a) 
Instance details

Defined in Database.PostgreSQL.Simple.Migration