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

feat!(db): database configuration for per-guild settings #33

Merged
merged 15 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ DEBUG=True

# --- Database Settings
# Prefix is ``DB_`` for all Database settings
DB_URL=
DB_USER=byte
DB_PASSWORD=bot
DB_HOST=localhost
DB_PORT=5432
DB_NAME=byte
DB_URL=postgresql+asyncpg://byte:bot@localhost:5432/byte
DB_MIGRATION_DDL_VERSION_TABLE=ddl_version

# Database Debugging Settings
# This is pretty noisy, so we'll leave it off by default
DB_ECHO=False
# This is pretty noisy, so we'll leave it off by default
DB_ECHO_POOL=False

# --- Server Settings
# Prefix is ``SERVER_`` for all Server settings
Expand All @@ -33,7 +45,3 @@ LOG_LEVEL=10

# --- OpenAPI Settings
# Prefix is ``OPENAPI_`` for all OpenAPI settings


# --- HTTP Settings
# Prefix is ``HTTP_`` for all HTTP Client settings
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ repos:
typing-extensions,
"uvicorn[standard]",
uvloop>=0.18.0,
litestar,
asyncpg,
"litestar[cli,structlog,standard]",
types-click,
asyncpg-stubs,
polyfactory,
discord-py,
]
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ docs: docs-clean ## Dump the existing built docs and rebuild them
@echo "=> Building documentation"
@$(PDM_RUN_BIN) sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going

# =============================================================================
# Database
# =============================================================================
migrations: ## Generate database migrations
@echo "ATTENTION: This operation will create a new database migration for any defined models changes."
@while [ -z "$$MIGRATION_MESSAGE" ]; do read -r -p "Migration message: " MIGRATION_MESSAGE; done ;
@$(ENV_PREFIX)app database make-migrations --autogenerate -m "$${MIGRATION_MESSAGE}"

.PHONY: migrate
migrate: ## Apply database migrations
@echo "ATTENTION: Will apply all database migrations."
@$(ENV_PREFIX)app database upgrade

# =============================================================================
# Main
# =============================================================================
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.infra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3.9"

services:
db:
image: postgres:latest
ports:
- "5432:5432"
hostname: db
environment:
POSTGRES_USER: "byte"
POSTGRES_PASSWORD: "bot"
POSTGRES_DB: "byte"

volumes:
- db-data:/var/lib/postgresql/data
restart: unless-stopped

logging:
options:
max-size: 10m
max-file: "3"

healthcheck:
test:
- CMD
- pg_isready
- -U
- byte
interval: 2s
timeout: 3s
retries: 40

volumes:
db-data: {}
cache-data: {}
51 changes: 42 additions & 9 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,39 @@ All commits to this project will be documented in this file.
[unreleased]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

`860bd65 <https://github.com/JacobCoffee/byte/commit/860bd656b438e546d552c7f6a090a2cd0719a6f0>`_ ... `860bd65 <https://github.com/JacobCoffee/byte/commit/>`_ | `See diff for <https://github.com/JacobCoffee/byte/compare/860bd656b438e546d552c7f6a090a2cd0719a6f0...>`_
Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`b84431d <https://github.com/JacobCoffee/byte/commit/b84431dd6ef3d80cd1f933bb4ede8b45090a3377>`_) - Update repo link (Jacob Coffee)
* (`d2de3b7 <https://github.com/JacobCoffee/byte/commit/d2de3b7e93bf697c66c8e0acb9780708669f1fa4>`_) - Mention specified user instead of author of command (Jacob Coffee)
* (`a138f5b <https://github.com/JacobCoffee/byte/commit/a138f5b9854b156a001bd31a3b19455e68b3f3bc>`_) - Use correct user for healthcheck (Jacob Coffee)
* (`e95da39 <https://github.com/JacobCoffee/byte/commit/e95da39d7f89631ee19a5aead6f66d0abe065816>`_) - Use correct types (Jacob Coffee)

Features
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`a06c77f <https://github.com/JacobCoffee/byte/commit/a06c77f781d613fde497e5ff9eb4f5abd27fd576>`_) - Adds a new slash command for performing a global sync (#27) (Alc-Alc)
* (`e936605 <https://github.com/JacobCoffee/byte/commit/e936605e97474a89f90162261148bda1652c82c3>`_) - Add ``mcve`` command (#30) (Jacob Coffee)
* (`96bcf7e <https://github.com/JacobCoffee/byte/commit/96bcf7ed3ace5763a85e1c6af16db073ba2bed62>`_) - Add helper function for markdown links (Jacob Coffee)
* (`d03b845 <https://github.com/JacobCoffee/byte/commit/d03b845439fa5ee5676edabfd1bdc904ce376e59>`_) - Flesh out db schema more (Jacob Coffee)

Miscellaneous Tasks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`fe08181 <https://github.com/JacobCoffee/byte/commit/fe0818199634b93e1280715b5d14fdffd1ced63d>`_) - Remove unused module (Jacob Coffee)
* (`9520e93 <https://github.com/JacobCoffee/byte/commit/9520e9305d6244022a989dbcb09bd6d2add82888>`_) - Initial migration schema (Jacob Coffee)
* (`4c7676e <https://github.com/JacobCoffee/byte/commit/4c7676e7fa38b76284f199d864bab534f766e0c2>`_) - Clean up imports (Jacob Coffee)

Infra
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`bba35b8 <https://github.com/JacobCoffee/byte/commit/bba35b8cae53455c848861194b1d1b01f8b7ef63>`_) - Update railway config for db (Jacob Coffee)

`Release [v0.3.0] - 2023-11-20 <https://github.com/JacobCoffee/byte/releases/tag/v0.3.0>`_
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* `See All commits in v0.3.0 <https://github.com/JacobCoffee/byte/commits/v0.3.0>`_

`860bd65 <https://github.com/JacobCoffee/byte/commit/860bd656b438e546d552c7f6a090a2cd0719a6f0>`_ ... `d30c1d7 <https://github.com/JacobCoffee/byte/commit/d30c1d78933c78eba8235a167bbd07a83005dfcc>`_ | `See diff for v0.3.0 <https://github.com/JacobCoffee/byte/compare/860bd656b438e546d552c7f6a090a2cd0719a6f0...d30c1d78933c78eba8235a167bbd07a83005dfcc>`_

Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -16,13 +48,14 @@ Bug Fixes
* (`fb95f02 <https://github.com/JacobCoffee/byte/commit/fb95f0241458b0fc53d36d44b9b6111e183113ff>`_) - Replace incorrect repo links (Jacob Coffee)
* (`f9ee620 <https://github.com/JacobCoffee/byte/commit/f9ee620e3d98b991fdc1f0d978c104245f3109bd>`_) - Replace incorrect repo link (Jacob Coffee)
* (`2be3030 <https://github.com/JacobCoffee/byte/commit/2be3030f25de18a6ec343db62e5bff98536160e4>`_) - Update links (Jacob Coffee)
* (`ae4ec60 <https://github.com/JacobCoffee/byte/commit/ae4ec6015866826acfbceb9a9cead55e708c9664>`_) - Resolve hybrid commands not displaying slash commands (#26) (Alc-Alc), Co-authored-by:Alc-Alc <alc@localhost>
* (`ae4ec60 <https://github.com/JacobCoffee/byte/commit/ae4ec6015866826acfbceb9a9cead55e708c9664>`_) - Resolve hybrid commands not displaying slash commands (#26) (Alc-Alc)
* (`d30c1d7 <https://github.com/JacobCoffee/byte/commit/d30c1d78933c78eba8235a167bbd07a83005dfcc>`_) - Update deps (Jacob Coffee)

`Release [v0.2.0] - 2023-11-15 <https://github.com/JacobCoffee/byte/releases/tag/v0.2.0>`_
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* `See All commits in v0.2.0 <https://github.com/JacobCoffee/byte/commits/v0.2.0>`_

`f175b4a <https://github.com/JacobCoffee/byte/commit/f175b4ac69de862682b8c2f82e7518562365ae5c>`_ ... `f175b4a <https://github.com/JacobCoffee/byte/commit/860bd656b438e546d552c7f6a090a2cd0719a6f0>`_ | `See diff for v0.2.0 <https://github.com/JacobCoffee/byte/compare/f175b4ac69de862682b8c2f82e7518562365ae5c...860bd656b438e546d552c7f6a090a2cd0719a6f0>`_
`f175b4a <https://github.com/JacobCoffee/byte/commit/f175b4ac69de862682b8c2f82e7518562365ae5c>`_ ... `860bd65 <https://github.com/JacobCoffee/byte/commit/860bd656b438e546d552c7f6a090a2cd0719a6f0>`_ | `See diff for v0.2.0 <https://github.com/JacobCoffee/byte/compare/f175b4ac69de862682b8c2f82e7518562365ae5c...860bd656b438e546d552c7f6a090a2cd0719a6f0>`_

Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -32,18 +65,18 @@ Bug Fixes
Documentation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`97bac28 <https://github.com/JacobCoffee/byte/commit/97bac2821cbb43b53162e7c3e577c80d80a847bc>`_) - Add allcontributors[bot] as a contributor for projectManagement (#18) (allcontributors[bot]), Co-authored-by:allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>, Co-authored-by:Jacob Coffee <[email protected]>
* (`c3ce850 <https://github.com/JacobCoffee/byte/commit/c3ce85064e26384b7e3dc338e3c2ead7a127a462>`_) - Add Alc-Alc as a contributor for code, and ideas (#19) (allcontributors[bot]), Co-authored-by:allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>, Co-authored-by:Jacob Coffee <[email protected]>
* (`97bac28 <https://github.com/JacobCoffee/byte/commit/97bac2821cbb43b53162e7c3e577c80d80a847bc>`_) - Add allcontributors[bot] as a contributor for projectManagement (#18) (allcontributors[bot])
* (`c3ce850 <https://github.com/JacobCoffee/byte/commit/c3ce85064e26384b7e3dc338e3c2ead7a127a462>`_) - Add Alc-Alc as a contributor for code, and ideas (#19) (allcontributors[bot])
* (`71a04f2 <https://github.com/JacobCoffee/byte/commit/71a04f241ca8d2bc3a26cd39472eef4c0fd60f2f>`_) - Update readme (Jacob Coffee)
* (`c590288 <https://github.com/JacobCoffee/byte/commit/c5902885ab1cca187090ec1e1dfe2a4801fd804c>`_) - Reenable packaages (Jacob Coffee)
* (`afef867 <https://github.com/JacobCoffee/byte/commit/afef867dce1dcaea9ff37b120ed416f518182a60>`_) - Update to latest (#20) (Jacob Coffee), Co-authored-by:Alc-Alc <[email protected]>, Co-authored-by:Alc-Alc <alc@localhost>
* (`c139ff6 <https://github.com/JacobCoffee/byte/commit/c139ff6067f06080003a08989b21bf73321a221c>`_) - Add Alc-Alc as a contributor for infra (#23) (allcontributors[bot]), Co-authored-by:allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
* (`dde5c87 <https://github.com/JacobCoffee/byte/commit/dde5c87d73e1378be9356767d4cabb89b73bde22>`_) - Add JacobCoffee as a contributor for doc, infra, and 2 more (#24) (allcontributors[bot]), Co-authored-by:allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
* (`afef867 <https://github.com/JacobCoffee/byte/commit/afef867dce1dcaea9ff37b120ed416f518182a60>`_) - Update to latest (#20) (Jacob Coffee)
* (`c139ff6 <https://github.com/JacobCoffee/byte/commit/c139ff6067f06080003a08989b21bf73321a221c>`_) - Add Alc-Alc as a contributor for infra (#23) (allcontributors[bot])
* (`dde5c87 <https://github.com/JacobCoffee/byte/commit/dde5c87d73e1378be9356767d4cabb89b73bde22>`_) - Add JacobCoffee as a contributor for doc, infra, and 2 more (#24) (allcontributors[bot])

Features
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* (`603d644 <https://github.com/JacobCoffee/byte/commit/603d644ae057fa5a6fe586e80be5dee0a6d3ab49>`_) - Add ``!`` as command prefix in addition to an env specific command prefix (#15) (Alc-Alc), Co-authored-by:Alc-Alc <alc@localhost>
* (`603d644 <https://github.com/JacobCoffee/byte/commit/603d644ae057fa5a6fe586e80be5dee0a6d3ab49>`_) - Add ``!`` as command prefix in addition to an env specific command prefix (#15) (Alc-Alc)
* (`211f50f <https://github.com/JacobCoffee/byte/commit/211f50fc685054d7508ed283ca7693945946c2a3>`_) - Replace help thread with embed (#16) (Jacob Coffee)

Miscellaneous Tasks
Expand Down
6 changes: 6 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

import importlib.metadata
import os
import warnings

from sqlalchemy.exc import SAWarning

from src.__metadata__ import __project__

# -- Environmental Data ------------------------------------------------------
warnings.filterwarnings("ignore", category=SAWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning) # RemovedInSphinx80Warning

# -- Project information -----------------------------------------------------
project = __project__
Expand All @@ -28,6 +33,7 @@
"sphinx_toolbox.collapse",
"sphinx_design",
"sphinxcontrib.autodoc_pydantic",
"sphinx_sqlalchemy",
]

exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
Expand Down
13 changes: 13 additions & 0 deletions docs/web/api/domain/db/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
========
Database
========

This is the database layer serving all domains in the application.

.. toctree::
:titlesonly:
:caption: Database Domain API Reference
:glob:
:hidden:

*
33 changes: 33 additions & 0 deletions docs/web/api/domain/db/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
======
models
======

Model definition for the domain.

API Reference
-------------

.. automodule:: src.server.domain.db.models
:members:

Model Reference
---------------

.. sqla-model:: src.server.domain.db.models.GuildConfig

.. sqla-model:: src.server.domain.db.models.GuildGitHubConfig

.. sqla-model:: src.server.domain.db.models.GitHubConfig

.. sqla-model:: src.server.domain.db.models.GuildSOTagsConfig

.. sqla-model:: src.server.domain.db.models.SOTagConfig

.. sqla-model:: src.server.domain.db.models.GuildAllowedUsersConfig

.. sqla-model:: src.server.domain.db.models.User

Mermaid Diagram
---------------

.. autoclasstree:: src.server.domain.db.models
15 changes: 15 additions & 0 deletions docs/web/api/domain/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
======
domain
======


.. toctree::
:titlesonly:
:caption: Domain API Reference
:hidden:

init
urls
system/index
web/index
db/index
21 changes: 2 additions & 19 deletions docs/web/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,5 @@ API Reference
cli
metadata
utils

.. toctree::
:titlesonly:
:caption: Domain API Reference
:glob:
:hidden:

domain/*
domain/web/index
domain/system/index

.. toctree::
:titlesonly:
:caption: Library API Reference
:glob:
:hidden:

lib/*
lib/log/index
domain/index
lib/index
9 changes: 9 additions & 0 deletions docs/web/api/lib/db/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
====
base
====

API Reference
-------------

.. automodule:: src.server.lib.db.base
:members:
12 changes: 12 additions & 0 deletions docs/web/api/lib/db/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
================
Database Library
================

Documentation for the Database library.


.. toctree::
:titlesonly:

base
orm
9 changes: 9 additions & 0 deletions docs/web/api/lib/db/orm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
===
orm
===

API Reference
-------------

.. automodule:: src.server.lib.db.orm
:members:
20 changes: 20 additions & 0 deletions docs/web/api/lib/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
===
lib
===


.. toctree::
:titlesonly:
:caption: Library API Reference
:hidden:

cors
exceptions
openapi
schema
serialization
settings
static_files
template
log/index
db/index
Loading
Loading