Skip to content

Commit

Permalink
Jobs reorg (#55)
Browse files Browse the repository at this point in the history
* Update Jobs for postgres split

* Reorder see also

* Update Package.swift

* Update Package.swift again

* Update Package.swift again
  • Loading branch information
adam-fowler committed Sep 17, 2024
1 parent c5bf0c6 commit 5a0af85
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
13 changes: 4 additions & 9 deletions Hummingbird.docc/HummingbirdPostgres/HummingbirdPostgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@

Working with Postgres databases.

`HummingbirdPostgres` provides a Postgres implementation of the persist framework and a Postgres database migration service. It uses `PostgresClient` from [PostgresNIO](https://github.com/vapor/postgres-nio) as its database client.
`HummingbirdPostgres` provides a Postgres implementation of the persist framework. It uses `PostgresClient` from [PostgresNIO](https://github.com/vapor/postgres-nio) as its database client.

## Topics

### Articles

- <doc:MigrationsGuide>
- <doc:PersistentData>

### Persist

- ``PostgresPersistDriver``

### Migrations

- ``PostgresMigrations``
- ``PostgresMigration``
- ``PostgresMigrationGroup``
- ``PostgresMigrationError``

## See Also

- ``Hummingbird``
- ``JobsPostgres``
- ``PostgresMigrations``

2 changes: 1 addition & 1 deletion Hummingbird.docc/Jobs/JobQueueDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Defines the requirements for job queue implementation.

### Jobs

- ``push(_:)``
- ``push(_:options:)``
- ``finished(jobId:)``
- ``failed(jobId:error:)``

Expand Down
2 changes: 1 addition & 1 deletion Hummingbird.docc/JobsPostgres/JobsPostgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hummingbird Jobs Queue driver using Postgres.

## See Also

- ``Hummingbird``
- ``Jobs``
- ``JobsRedis``
- ``Hummingbird``
- ``HummingbirdPostgres``
3 changes: 1 addition & 2 deletions Hummingbird.docc/JobsRedis/JobsRedis.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Hummingbird Jobs Queue driver using Redis queues.

## See Also

- ``Hummingbird``
- ``Jobs``
- ``JobsPostgres``
- ``HummingbirdRedis``
- ``Hummingbird``
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Database migrations are a controlled set of incremental changes applied to a dat
Each migration includs an `apply` method that applies the change and a `revert` method that reverts the change.

```swift
struct CreateMyTableMigration: PostgresMigration {
struct CreateMyTableMigration: DatabaseMigration {
func apply(connection: PostgresConnection, logger: Logger) async throws {
try await connection.query(
"""
Expand All @@ -39,12 +39,12 @@ As an individual migration can be dependent on the results of a previous migrati

### Adding migrations

You need to create a ``HummingbirdPostgres/PostgresMigrations`` object to store your migrations in. Only create one of these, otherwise you could confuse your database about what migrations need applied. Adding a migration is as simple as calling `add`.
You need to create a ``/PostgresMigrations/DatabaseMigrations`` object to store your migrations in. Only create one of these, otherwise you could confuse your database about what migrations need applied. Adding a migration is as simple as calling `add`.

```swift
import HummingbirdPostgres

let migrations = PostgresMigrations()
let migrations = DatabaseMigrations()
await migrations.add(CreateMyTableMigration())
```

Expand All @@ -65,18 +65,18 @@ You will notice in the code above the parameter `dryRun` is set to true. This is
### Reverting migrations

There are a number of situations where a migration maybe reverted.
- The user calls ``HummingbirdPostgres/PostgresMigrations/revert(client:groups:logger:dryRun:)``. This will revert all the migrations applied to the database.
- A user removes a migration from the list. The migration still needs to be registered with the migration system as it needs to know how to revert that migration. This is done with a call to ``HummingbirdPostgres/PostgresMigrations/register(_:)``. When a migration is removed it is reverted and all subsequent migrations will be reverted and then re-applied.
- The user calls ``/PostgresMigrations/DatabaseMigrations/revert(client:groups:logger:dryRun:)``. This will revert all the migrations applied to the database.
- A user removes a migration from the list. The migration still needs to be registered with the migration system as it needs to know how to revert that migration. This is done with a call to ``/PostgresMigrations/DatabaseMigrations/register(_:)``. When a migration is removed it is reverted and all subsequent migrations will be reverted and then re-applied.
- A user changes the order of migrations. This is generally a user error, but if it is intentional then the first migration affected by the order change and all subsequent migrations will be reverted and then re-applied.

### Migration groups

A migration group is a group of migrations that can be applied to a database independent of all other migrations outside that group. By default all migrations are added to the `.default` migration group. Each group is applied independently to your database. A group allows for a modular piece of code to add additional migrations without affecting the ordering of other migrations and causing deletion of data.

To create a group you need to extend `PostgresMigrationGroup` and add a new static variable for the migration group id.
To create a group you need to extend `/PostgresMigrations/DatabaseMigrationsGroup` and add a new static variable for the migration group id.

```swift
extension PostgresMigrationGroup {
extension DatabaseMigrationGroup {
public static var myGroup: Self { .init("my_group") }
}
```
Expand All @@ -85,7 +85,7 @@ Then every migration that belongs to that group must set its group member variab

```swift
extension CreateMyTableMigration {
var group: PostgresMigrationGroup { .myGroup }
var group: DatabaseMigrationGroup { .myGroup }
}
```

Expand All @@ -95,6 +95,6 @@ The persist and job queue drivers that come with HummingbirdPostgres both use gr

### Reference

- ``HummingbirdPostgres/PostgresMigrations``
- ``HummingbirdPostgres/PostgresMigration``
- ``HummingbirdPostgres/PostgresMigrationGroup``
- ``/PostgresMigrations/DatabaseMigrations``
- ``/PostgresMigrations/DatabaseMigration``
- ``/PostgresMigrations/DatabaseMigrationGroup``
24 changes: 24 additions & 0 deletions Hummingbird.docc/PostgresMigrations/PostgresMigrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ``PostgresMigrations``

Postgres database migration service

@Metadata {
@PageImage(purpose: icon, source: "logo")
}
## Topics

### Articles

- <doc:MigrationsGuide>

### Migrations

- ``DatabaseMigrations``
- ``DatabaseMigration``
- ``DatabaseMigrationGroup``
- ``DatabaseMigrationError``

## See Also

- ``HummingbirdPostgres``
- ``Hummingbird``
14 changes: 8 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ let package = Package(
targets: ["HummingbirdDocs"]),
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.1"),
.package(url: "https://github.com/hummingbird-project/hummingbird-auth.git", from: "2.0.0-rc.3"),
.package(url: "https://github.com/hummingbird-project/hummingbird-compression.git", from: "2.0.0-rc.1"),
.package(url: "https://github.com/hummingbird-project/hummingbird-compression.git", from: "2.0.0-rc.2"),
.package(url: "https://github.com/hummingbird-project/hummingbird-fluent.git", from: "2.0.0-beta.3"),
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.2"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-redis.git", from: "1.0.0-beta.4"),
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.4"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-postgres.git", from: "1.0.0-beta.1"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-redis.git", from: "1.0.0-beta.6"),
.package(url: "https://github.com/hummingbird-project/hummingbird-lambda.git", from: "2.0.0-rc.3"),
.package(url: "https://github.com/hummingbird-project/swift-mustache.git", from: "2.0.0-beta.1"),
.package(url: "https://github.com/hummingbird-project/hummingbird-postgres.git", from: "0.4.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-postgres.git", from: "0.5.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-redis.git", from: "2.0.0-beta.4"),
.package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
Expand All @@ -44,11 +45,12 @@ let package = Package(
.product(name: "HummingbirdFluent", package: "hummingbird-fluent"),
.product(name: "Jobs", package: "swift-jobs"),
.product(name: "JobsRedis", package: "swift-jobs-redis"),
.product(name: "JobsPostgres", package: "swift-jobs-postgres"),
.product(name: "HummingbirdLambda", package: "hummingbird-lambda"),
.product(name: "HummingbirdLambdaTesting", package: "hummingbird-lambda"),
.product(name: "Mustache", package: "swift-mustache"),
.product(name: "HummingbirdPostgres", package: "hummingbird-postgres"),
.product(name: "JobsPostgres", package: "hummingbird-postgres"),
.product(name: "PostgresMigrations", package: "hummingbird-postgres"),
.product(name: "HummingbirdRedis", package: "hummingbird-redis"),
.product(name: "HummingbirdWebSocket", package: "hummingbird-websocket"),
.product(name: "HummingbirdWSClient", package: "hummingbird-websocket"),
Expand Down
1 change: 1 addition & 0 deletions scripts/build-docc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if test "$BUILD_SYMBOLS" == 1; then
cp $SG_FOLDER/Jobs* $HB_SG_FOLDER
cp $SG_FOLDER/OTP* $HB_SG_FOLDER
cp $SG_FOLDER/Bcrypt* $HB_SG_FOLDER
cp $SG_FOLDER/PostgresMigrations* $HB_SG_FOLDER
#rm $HB_SG_FOLDER/*@*
fi

Expand Down

0 comments on commit 5a0af85

Please sign in to comment.