| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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
- data MigrationConfig = MigrationConfig {}
- defaultMigrationConfig :: MigrationConfig
- runMigrationsForRegistry :: forall (registry :: JobPayloadRegistry). RegistryTables registry => Proxy registry -> ByteString -> Text -> MigrationConfig -> IO (MigrationResult String)
- runMigrationsTrackedForTables :: ByteString -> Text -> [Text] -> MigrationConfig -> IO (MigrationResult String)
- jobQueueMigrationsForTable :: Text -> Text -> MigrationConfig -> [MigrationCommand]
- data MigrationResult a
Configuration
data MigrationConfig Source #
Configuration for job queue migrations
Controls which optional features are enabled when creating job queue tables.
Constructors
| MigrationConfig | |
Fields
| |
Instances
| Show MigrationConfig Source # | |
Defined in Arbiter.Migrations Methods showsPrec :: Int -> MigrationConfig -> ShowS # show :: MigrationConfig -> String # showList :: [MigrationConfig] -> ShowS # | |
| Eq MigrationConfig Source # | |
Defined in Arbiter.Migrations Methods (==) :: MigrationConfig -> MigrationConfig -> Bool # (/=) :: MigrationConfig -> MigrationConfig -> Bool # | |
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 #
Constructors
| MigrationError a | |
| MigrationSuccess |