PostgreSQL driver, tests against DB backends, and general drivers cleanup #2723
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2723
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/postgres_driver"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Yay! The PostgreSQL driver is here. This comes with quite a few changes to the driver system, the data backup/migration/deletion system, and tests. The reason I made so many changes is because I wanted to harmonise backend-agnostic operations rather than add more driver-specific code where it didn't need to be. There are also just a few general cleanups in here too for the other drivers. This includes breaking changes for any dev using the drivers directly, but I think devs who are doing so should expect such breaking changes to occur (it's not exactly an interface we encourage devs to use).
The PostgreSQL driver
"cog_name.cog_identifier".red_cogstable in thered_configschema, to track which schemas actually contain red data, and to assist with migrations.redbot/core/driver/postgres/ddl.sqlcontains all of the actual logic behind the driver, mostly in PL/pgSQL. At least we're diversifying our code base 😉inc()andtoggle()methods in anticipation for #2635.Changes to drivers more generally
red_prefix. Also, driver classes are now available as attributes to theredbot.core.driverspackage, and extra requirements (motor, asyncpg) are imported conditionally.redbot.core.driverspackage:get_driver()now takes the cog name, identifier, driver-specific kwargs (if needed) and an optionalstorage_typekwarg. Ifstorage_typeis omitted, the function will default todata_manager.storage_type().get_driver_class(), which simply takes an optionalstorage_typeand returns the class for the driver.BaseDriver.get_config_details()is now an abstract staticmethod. With the Mongo driver, for some reason it was a module-level function, and was being called in a non-abstract and non-agnostic way.BaseDriver.initialize(**storage_details)andBaseDriver.teardown()are two new abstract coroutine classmethods to initialise and teardown the driver (db connections, DDL etc). For the JSON driver, these do nothing.BaseDriver.initialize()will raise a new exception,redbot.core.errors.MissingExtraRequirements, when the required extra has not been installed for that driver.data_path_overridekwarg to create standard drivers for a settings file in a core/cog data path. The kwarg is still available, however (for unit tests).IdentifierData.custom_group_datais no longer a dict, has been renamed toIdentifierData.primary_key_lenand will always be an int (it was actually unclear what it was meant to be beforehand). This simplifies quite a bit of code where the primary key length is needed. Also,ConfigCategory.get_pkey_info()is a new classmethod for the enum which returns a(primary_key_len, is_custom)tuple based on the passed category and custom group data dict.BaseDriver.delete_all_data()is a new coroutine method for deleting all data from the given backend. There is a generic implementation of this in the base driver, but the Mongo and Postgres drivers have overridden methods with extra options (e.g. allowing the data to be deleted by simply dropping the entire database). This replaces the logic which was previously inredbot.setup.remove_instance()BaseDriver.aiter_cogs()is an abstract asynchonous iterator which yields (cog_name, cog_id) tuples which refer to cogs which have data stored on that driver's backend. This is useful for migrations, as discussed below.BaseDriver.migrate_to()is a new coroutine method which is a driver-agnostic (non-abstract) way of migrating data from one backend to another. It makes use of the newBaseDriver.aiter_cogs()method and existingBaseDriver.(import|export)_data()methods. Further discussed below.Changes to migrations and backups
redbot.setup, except for that regarding MongoV1, has been removed.redbot.core.config.migrate()is a new coroutine function for migrating from one driver to another. It usesBaseDriver.migrate_to()under the hood, but abstracts away the retrieval of custom group data. It is used to migrate data to the JSON driver prior to a backup.[p]backupcommand no longer contains driver-specific codeBaseDriverABC.Unit tests
-eoption or theTOXENVenv var. Options for the driver backend can be modified through environment variables (see tox.ini). Travis now has two extra jobs for these extra tox recipes.tests/conftest.pyhas been added back in because pytest-asyncio is doing weird shit with theevent_loopfixture (see pytest-dev/pytest-asyncio#75). It also contains the important new (autouse) fixture for setting up and tearing down the drivers. Now this may cause issues with 3rd party cog test suites which are making use of our fixtures, but I doubt it.That's it. I'm sorry it's such a massive PR. But all of these changes ultimately made it much easier to write and verify the new driver.
@mikeshardmind The next PR for Config I do will be reorganising config into a package with the drivers as a private subpackage. I think that should be sufficient
Appears to work as intended, I still have a few more things to look at before I'm confident enough for a 👍 though.
After the stuff which was brought up in discord was handled (ident based auth support, not requiring being a pg superuser) This is now ready for use.