| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Migrations
Description
Versioned, tracked migrations for job queue schemas, run once in order.
History lives in a schema_migrations table inside the target schema.
Each run also seeds the admission policies and reconciles the rate-limit durability
and optional triggers in MigrationConfig.
Synopsis
- data MigrationConfig = MigrationConfig {}
- defaultMigrationConfig :: MigrationConfig
- runMigrationsForRegistry :: forall (registry :: JobPayloadRegistry). (RegistryAdmissionPolicies registry, RegistryTables registry) => Proxy registry -> ByteString -> SchemaName -> MigrationConfig -> IO (MigrationResult String)
- runMigrationsTrackedForTables :: ByteString -> SchemaName -> [(TableName, TableAdmission)] -> MigrationConfig -> AdmissionSeeds -> IO (MigrationResult String)
- jobQueueMigrationsForTable :: SchemaName -> TableName -> TableAdmission -> [MigrationCommand]
- schemaLevelMigrations :: SchemaName -> [MigrationCommand]
- data AdmissionSeeds = AdmissionSeeds {}
- noAdmissionSeeds :: AdmissionSeeds
- data TableAdmission = TableAdmission {}
- allTableAdmission :: TableAdmission
- validateRegistryNames :: SchemaName -> [TableName] -> Either Text ()
- maxQueueNameBytes :: Int
- conflictingPolicyPrefixes :: [RateLimitPolicy] -> [Text]
- data QueueSpec = QueueWithResult Symbol Type Type
- type Queue (table :: Symbol) payload = 'QueueWithResult table payload ()
- data MigrationCommand
- data MigrationResult a
- data Durability
- data RateLimitPolicy = RateLimitPolicy {}
- data ConcurrencyPolicy = ConcurrencyPolicy {}
- type SchemaName = Text
- type TableName = Text
Configuration
data MigrationConfigSource #
Migration options and the desired state reconciled after a schema's tracked migrations run.
Constructors
| MigrationConfig | |
Fields
| |
Instances
| Eq MigrationConfig Source # | |
Defined in Arbiter.Migrations Methods (==) :: MigrationConfig -> MigrationConfig -> Bool# (/=) :: MigrationConfig -> MigrationConfig -> Bool# | |
| Show MigrationConfig Source # | |
Defined in Arbiter.Migrations Methods showsPrec :: Int -> MigrationConfig -> ShowS# show :: MigrationConfig -> String# showList :: [MigrationConfig] -> ShowS# | |
defaultMigrationConfig :: MigrationConfigSource #
Notify triggers on, event streaming off, unlogged rate-limit buckets, no lock timeout.
Tracked migrations
runMigrationsForRegistry :: forall (registry :: JobPayloadRegistry). (RegistryAdmissionPolicies registry, RegistryTables registry) => Proxy registry -> ByteString -> SchemaName -> MigrationConfig -> IO (MigrationResult String)Source #
Arguments
| :: forall (registry :: JobPayloadRegistry). (RegistryAdmissionPolicies registry, RegistryTables registry) | |
| => Proxy registry | Proxy for the job payload registry |
| -> ByteString | Database connection string |
| -> SchemaName | Schema for the arbiter tables |
| -> MigrationConfig | Migration options |
| -> IO (MigrationResult String) |
Migrate every queue in a registry into one schema. The schema itself is created
first, outside migration tracking. Names that fail validateRegistryNames return
MigrationError before the connection opens.
type AppRegistry =
'[ Queue "email_jobs" EmailPayload
, Queue "order_jobs" OrderPayload
]
main :: IO ()
main = do
result <- runMigrationsForRegistry
(Proxy @AppRegistry)
"host=localhost dbname=mydb"
"arbiter"
defaultMigrationConfig
print result
runMigrationsTrackedForTables :: ByteString -> SchemaName -> [(TableName, TableAdmission)] -> MigrationConfig -> AdmissionSeeds -> IO (MigrationResult String)Source #
Arguments
| :: ByteString | Database connection string |
| -> SchemaName | Schema for the arbiter tables |
| -> [(TableName, TableAdmission)] | Every queue table in the schema, with its admission trigger kinds |
| -> MigrationConfig | Migration options |
| -> AdmissionSeeds | Admission policy rows to seed |
| -> IO (MigrationResult String) |
Migrate several tables in one schema. On success, seed the policies, then reconcile
durability and triggers on the same connection. The table list must be the schema's
whole queue set. An omitted queue loses its notify and event-streaming objects.
Names that fail validateRegistryNames return MigrationError before the
connection opens.
jobQueueMigrationsForTable :: SchemaName -> TableName -> TableAdmission -> [MigrationCommand]Source #
Arguments
| :: SchemaName | Schema for the arbiter tables |
| -> TableName | Queue table name |
| -> TableAdmission | Which admission trigger kinds to install |
| -> [MigrationCommand] |
One queue's tracked migrations, each under its own version identifier. The optional notify and event-streaming objects are reconciled after the migrations run.
schemaLevelMigrations :: SchemaName -> [MigrationCommand]Source #
The schema-level migrations, run once per schema. The optional notification and event-streaming objects are reconciled after the migrations run.
data AdmissionSeedsSource #
Admission policy rows to seed after a successful migration.
Constructors
| AdmissionSeeds | |
Fields
| |
noAdmissionSeeds :: AdmissionSeedsSource #
Seeds for a deployment with no admission policies.
data TableAdmissionSource #
Which admission trigger kinds a table's payload declares. Trigger migrations are install-only. A kind removed from a payload keeps its triggers.
Constructors
| TableAdmission | |
Fields
| |
Instances
| Eq TableAdmission Source # | |
Defined in Arbiter.Migrations Methods (==) :: TableAdmission -> TableAdmission -> Bool# (/=) :: TableAdmission -> TableAdmission -> Bool# | |
| Show TableAdmission Source # | |
Defined in Arbiter.Migrations Methods showsPrec :: Int -> TableAdmission -> ShowS# show :: TableAdmission -> String# showList :: [TableAdmission] -> ShowS# | |
allTableAdmission :: TableAdmissionSource #
Install every admission trigger kind.
Validation
validateRegistryNames :: SchemaName -> [TableName] -> Either Text ()Source #
Reject an empty or over-long schema name, and queue names that are empty, exceed
maxQueueNameBytes, generate a schema-wide arbiter table, or generate the same
object or channel name as another queue.
maxQueueNameBytes :: IntSource #
The longest queue name whose generated identifiers stay distinct after PostgreSQL
truncates them to maxIdentifierBytes.
conflictingPolicyPrefixes :: [RateLimitPolicy] -> [Text]Source #
Rate-limit policy prefixes declared with more than one parameter set.
Re-exports
A queue's table name, payload type, and handler result type. A type data
constructor. It takes no promotion tick.
Constructors
| QueueWithResult Symbol Type Type |
Instances
| RegistryTables ('[] :: [QueueSpec]) # | |
Defined in Arbiter.Core.QueueRegistry | |
| RegistryPolicies ('[] :: [QueueSpec]) p # | |
Defined in Arbiter.Core.Admission Methods registryTablePolicies :: [(Text, Set p)]# | |
| (HasKind (SpecPayload spec), KnownSymbol (SpecName spec), NotInPayloads (SpecPayload spec) rest, NotInTables (SpecName spec) rest, RegistryTables rest) => RegistryTables (spec ': rest) # | |
Defined in Arbiter.Core.QueueRegistry Methods registryTableNames :: Proxy (spec ': rest) -> [Text]# registryQueueKinds :: Proxy (spec ': rest) -> [(Text, [Text])]# | |
| (CollectFor (SpecPayload spec) p, KnownSymbol (SpecName spec), RegistryPolicies rest p) => RegistryPolicies (spec ': rest) p # | |
Defined in Arbiter.Core.Admission Methods registryTablePolicies :: [(Text, Set p)]# | |
type Queue (table :: Symbol) payload = 'QueueWithResult table payload ()#
A queue whose handlers store no result. A module with its own Queue type
needs import Arbiter.Core hiding (Queue) or a qualified import.
data MigrationCommand#
MigrationCommand determines the action of the runMigration script.
Constructors
| MigrationInitialization | Initializes the database with a helper table containing meta information. |
| MigrationDirectory FilePath | Executes migrations based on SQL scripts in the provided |
| MigrationFile ScriptName FilePath | Executes a migration based on script located at the provided
|
| MigrationScript ScriptName ByteString | Executes a migration based on the provided bytestring. |
| MigrationValidation MigrationCommand | Validates that the provided MigrationCommand has been executed. |
| MigrationCommands [MigrationCommand] | Performs a series of |
Instances
data MigrationResult a#
A sum-type denoting the result of a migration.
Constructors
| MigrationError a | There was an error in script migration. |
| MigrationSuccess | All scripts have been executed successfully. |
Instances
data Durability#
Whether the rate-limit bucket table is WAL-logged. Set by the migration config.
Constructors
| Durable | WAL-logged. Buckets survive a crash. |
| Unlogged | Not WAL-logged. A crash resets the buckets. The migrations use this by default. |
Instances
| Eq Durability # | |
Defined in Arbiter.Core.RateLimit.Spec | |
| Show Durability # | |
Defined in Arbiter.Core.RateLimit.Spec Methods showsPrec :: Int -> Durability -> ShowS# show :: Durability -> String# showList :: [Durability] -> ShowS# | |
data RateLimitPolicy#
A token-bucket policy. Burst policyMax, refilling continuously at policyRefill
per policyInterval. A policyRefill of 0 is a manually-refilled bucket. Fields are
non-negative and the interval is positive. The migration rejects other values.
Constructors
| RateLimitPolicy | |
Fields
| |
Instances
data ConcurrencyPolicy#
A concurrency policy. At most cpLimit jobs are in flight per key under cpPrefix. The
default is seeded. An operator override on the policy takes precedence.
Constructors
| ConcurrencyPolicy | |
Instances
type SchemaName = Text#
PostgreSQL schema name, e.g. "arbiter".