| 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.
Synopsis
- data QueueSpec = QueueWithResult Symbol Type Type
- type Queue (table :: Symbol) payload = 'QueueWithResult table payload ()
- data MigrationConfig = MigrationConfig {}
- defaultMigrationConfig :: MigrationConfig
- validateRegistryNames :: SchemaName -> [TableName] -> Either Text ()
- maxQueueNameBytes :: Int
- 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
- conflictingPolicyPrefixes :: [PolicyRow] -> [Text]
- data MigrationResult a
Registry
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.
Configuration
Source #data MigrationConfig
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 | |
Source #defaultMigrationConfig :: MigrationConfig
Notify triggers on, event streaming off, unlogged rate-limit buckets.
Source #validateRegistryNames :: SchemaName -> [TableName] -> Either Text ()
Reject queue names that generate a schema-wide arbiter table, or that generate object or channel names PostgreSQL truncates into each other. The length limit is where two of a queue's generated names collide.
Source #maxQueueNameBytes :: Int
The longest queue name whose generated identifiers survive PostgreSQL's 63-byte truncation distinct. Derived by rendering a probe queue's own DDL at each length.
Tracked Migrations
Source #runMigrationsForRegistry :: forall (registry :: JobPayloadRegistry). (RegistryAdmissionPolicies registry, RegistryTables registry) => Proxy registry -> ByteString -> SchemaName -> MigrationConfig -> IO (MigrationResult String)
Arguments
| :: forall (registry :: JobPayloadRegistry). (RegistryAdmissionPolicies registry, RegistryTables registry) | |
| => Proxy registry | Proxy for the job payload registry |
| -> ByteString | Database connection string |
| -> SchemaName | Schema name |
| -> MigrationConfig | Migration configuration |
| -> IO (MigrationResult String) | Migration results |
Migrate every queue in a registry into one schema. The schema itself is created first, outside migration tracking.
type AppRegistry =
'[ Queue "email_jobs" EmailPayload
, Queue "order_jobs" OrderPayload
]
main :: IO ()
main = do
result <- runMigrationsForRegistry
(Proxy @AppRegistry)
"host=localhost dbname=mydb"
"arbiter"
defaultMigrationConfig
Source #runMigrationsTrackedForTables :: ByteString -> SchemaName -> [(TableName, TableAdmission)] -> MigrationConfig -> AdmissionSeeds -> IO (MigrationResult String)
Run migrations for multiple tables within a single schema, seeding the given rate-limit policies. On migration success, reconciles the policy and bucket tables on the same connection. The table list must be the schema's whole queue set. Reconciliation treats an omitted queue as removed and drops its notify and event-streaming objects.
Source #jobQueueMigrationsForTable :: SchemaName -> TableName -> TableAdmission -> [MigrationCommand]
Arguments
| :: SchemaName | Schema name |
| -> TableName | Table name |
| -> TableAdmission | Which admission trigger kinds to install |
| -> [MigrationCommand] | List of migration commands |
One queue's tracked migrations, each under its own version identifier.
reconcileOptionalTriggers owns the optional notify and event-streaming objects.
Source #schemaLevelMigrations :: SchemaName -> [MigrationCommand]
The schema-level migrations, run once per schema. Exposed for the golden suite.
reconcileOptionalTriggers owns the optional notification and event-streaming
objects.
Source #data AdmissionSeeds
Admission policy rows to seed after a successful migration.
Constructors
| AdmissionSeeds | |
Fields | |
Source #noAdmissionSeeds :: AdmissionSeeds
Seeds for a deployment with no admission policies.
Source #data TableAdmission
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 | |
Source #allTableAdmission :: TableAdmission
Install every admission trigger kind.
Rate-limit reconciliation
Source #conflictingPolicyPrefixes :: [PolicyRow] -> [Text]
conflictingPrefixes specialized to policy rows.
Re-exports
#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. |