Skip to content

Commit

Permalink
Break out CLI functionality to make it modular + --line flag
Browse files Browse the repository at this point in the history
Here, break out the CLI so that most of its implementation no longer
lives in a `main.go`, and rather in a subpackage that can be imported
from somewhere else. This lets the majority of it to be reused in
another executable and augmented in various ways.

An addition is a new `DriverProcurer` interface that can provide a
driver for various databases:

    type DriverProcurer interface {
        ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx]
    }

For the main CLI, this gets a trivial implementation using `riverpgxv5`,
but could potentially be reimplemented elsewhere to swap in something
else;

    type DriverProcurer struct{}

    func (p *DriverProcurer) ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx] {
            return riverpgxv5.New(pool)
    }

To make this more workable, I end up going through and refactoring quite
a lot of code, making it into a bit of a mini framework, and one that
could potentially support additional databases in the future without
having to refactor the world again.

We also add a `--line` flag to support the feature from #435 to the CLI.
  • Loading branch information
brandur committed Jul 14, 2024
1 parent 18fbd7d commit 3f6ed01
Show file tree
Hide file tree
Showing 6 changed files with 659 additions and 514 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ river migrate-up --database-url "$DATABASE_URL"
- Fully functional driver for `database/sql` for use with packages like Bun and GORM. [PR #351](https://github.com/riverqueue/river/pull/351).
- Queues can be added after a client is initialized using `client.Queues().Add(queueName string, queueConfig QueueConfig)`. [PR #410](https://github.com/riverqueue/river/pull/410).
- Migration that adds a `line` column to the `river_migration` table so that it can support multiple migration lines. [PR #435](https://github.com/riverqueue/river/pull/435).
- `--line` flag added to the River CLI. [PR #454](https://github.com/riverqueue/river/pull/454).

### Changed

Expand Down
Loading

0 comments on commit 3f6ed01

Please sign in to comment.