Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create scaffolding for adding Postgres support #171

Merged
merged 12 commits into from
Jun 12, 2024

Commits on Jun 11, 2024

  1. Add 'postgres' flag and dummy Postgres module

    Add 'postgres' flag to:
    1. `make` targets:
      1. `make configure`
      1. `make /dist/bin/kupo`
    1. kupo.cabal:
      1. Conditionally include the Postgres module vs the SQLite module
      1. Add `cpp-options: -Dpostgres`
    1. Kupo.App.Database: import Postgres or SQLite module depending on flag
    
    Also add additional files to `make clean` to cause the project to be recompiled after `clean`
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    4bc9895 View commit details
    Browse the repository at this point in the history
  2. Move DB instantiation and aquisition logic into DB modules

    Previously, creating a SQLite DB file, creating read-only and read-write connection pools, and gatekeeping connection types (e.g., `ReadWrite`)
    against the Kupo instance type (e.g., read only replica) was exposed by the `SQLite` module and performed in `Kupo`.
    
    Now, those functions are encapsulated within the DB-specific modules to allow unique implementations. For instance, PostgreSQL does not have a DB file
    and does not need separate pools for read-only and read-write connections.
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    5bc0ce7 View commit details
    Browse the repository at this point in the history
  3. Provide DB-specific locations through conditional compilation

    Use a single data structure, `databaseLocation`, to describe either a work directory or in-memory when compiled for SQLite
    or a remote URL when compiled for PostgreSQL. This provides strong type safety but comes at the cost of having to include a
    argument parser in the DB modules, which is not really where it belongs. Alternatively, conditional compilation could be
    added to the argument parsing module, but that also seems out of place. Ultimately, including all 3 alternatives in
    `databaseLocation` and validating at runtime may be a cleaner solution, despite the loss of type safety.
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    30dbd60 View commit details
    Browse the repository at this point in the history
  4. Revert "Provide DB-specific locations through conditional compilation"

    This reverts commit 2701b34.
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    bfe6319 View commit details
    Browse the repository at this point in the history
  5. Create remote URL option for DB location

    Add a command line option to specify a remote URL as DB location instead of work directory
    or in memory. This was added as another sum type to the existing option to prevent additional
    conditional compilation and avoid the need to conditionally compile the option parser. This
    comes at the expense of type safety, as each DB module throws a runtime error if an
    incompatible DB Location is provided.
    
    Trace logging of the max concurrency configuration was kept in `Kupo` rather than the DB modules
    due to a cyclical dependency between `App/Configuration`, `SQLite`/`Postgres`, and `App/Database`.
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    129cec6 View commit details
    Browse the repository at this point in the history
  6. Create remote URL option for DB location

    Add a command line option to specify a remote URL as DB location instead of work directory
    or in memory. This was added as another sum type to the existing option to prevent additional
    conditional compilation and avoid the need to conditionally compile the option parser. This
    comes at the expense of type safety, as each DB module throws a runtime error if an
    incompatible DB Location is provided.
    
    Trace logging of the max concurrency configuration was kept in `Kupo` rather than the DB modules
    due to a cyclical dependency between `App/Configuration`, `SQLite`/`Postgres`, and `App/Database`.
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    c47801d View commit details
    Browse the repository at this point in the history
  7. Fix bugs in Makefile

    Clean whole build directory so cabal actually rebuilds the binary, and include the postgres flag in configure stage
    domMayhew authored and KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    6b9f250 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    e5fde65 View commit details
    Browse the repository at this point in the history
  9. reinstate in-memory custom string handles for testing.

      We cannot just use 'InMemory' for tests as this creates a shared in-memory database (each test therefore conflicting with one another). This is why the 'DatabaseFile' allows for passing an extra path to the InMemory variant. Not that having both 'DatabaseFile' and 'DatabaseLocation' feels somewhat redundant and just adds confusion overall. We shall perhaps consider getting rid of one.
    KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    c0c43da View commit details
    Browse the repository at this point in the history
  10. Fix newPool crashing due to 0 concurrent writers setting.

      Ideally, we should just not create any resource pool when in read-only mode. But the impact on the API is sufficiently annoying to not be worth it. So we still create a read/write pool which simply remains idle for the entire application lifetime. Yet we must ensure that the pool size is >= 1, otherwise it crashes at runtime. Yet, we don't want to report any writer capabilities in log.
    KtorZ committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    8a17ed3 View commit details
    Browse the repository at this point in the history

Commits on Jun 12, 2024

  1. Replace newDBPoolFromFile with newDBPool

    Including `newDBPoolFromFile` in the external API of `App/Database`
    creates issues for the Postgres module, which does not have any
    notion of a DB file. Instead, we add a `FilePath` to
    `Configuration.InMemory` but do not expose ability to provide a
    filepath to the command line. This allows us to provide a filepath
    for testing purposes but does allow the user to supply one, all
    while maintaining good abstraction boundaries.
    domMayhew committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    325efce View commit details
    Browse the repository at this point in the history
  2. Conditionally compile invalid command line options to be hidden

    Due to an issue with CPP, multiline string literals had to be replaced with
    concatenated single line literals.
    
    `internal` was used instead of `hidden` to hide the options from the
    long help text as well as the short help.
    domMayhew committed Jun 12, 2024
    Configuration menu
    Copy the full SHA
    dbfa027 View commit details
    Browse the repository at this point in the history