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

DQB-27 create weekly menu #38

Merged
merged 46 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6a89413
DQB-27 Created menu tables
jplhanna Aug 27, 2023
2e95562
Add initial implementation of MenuService
jplhanna Aug 29, 2023
3ae3884
DQB-27 Fix black alembic hook to no longer think line lenght is 79
jplhanna Sep 7, 2023
4a49dbb
Clean up DockerFile (#37)
jplhanna Dec 31, 2023
aba526b
Introduce initial retrieve tavern menu of the week support
Dec 31, 2023
ccb6307
Fix commit-msg hook
Dec 31, 2023
52fed6d
Created IntEnum model type
Dec 31, 2023
e7290d2
Update pre commit versions and set giticket mode
Dec 31, 2023
cdbd292
Update ars for giticket
Dec 31, 2023
15f9969
DQB-27 Test
Dec 31, 2023
966e7d5
Update MenuItem to use Enum and update Menu query to be more specific
Jan 1, 2024
8886509
Add menu data in tavern menu command response
Jan 1, 2024
c1f6811
DQB-27 Create test for menu item grouping property
Jan 1, 2024
49c91d1
DQB-27 Fix commit msg hooks
Jan 1, 2024
20574dc
DQB-27 Update gitlint rules
Jan 1, 2024
2a5e128
DQB-27 Write tests for the new menu retrieval command
Jan 1, 2024
10fe753
DQB-27 Migrate dictionary configuration to pydantic-settings
Jan 2, 2024
be247a7
DQB-27 Update poetry lock file with new package versions
Jan 2, 2024
7118513
DQB-27 Finish migration from dict based settings to pydantic
Jan 2, 2024
435588d
DQB-27 Update to better support local setup
jplhanna Jan 15, 2024
60a6ab9
DQB-27 Fix issues with the Pydantic Setings configuration
jplhanna Jan 15, 2024
c19445c
DQB-27 Enforce non empty strings in configuration
jplhanna Jan 16, 2024
0ed9494
DQB-27 Migrate to pydantic and SQLModel
jplhanna Jan 29, 2024
b65ee75
DQB-27 Updates to testing suite
jplhanna Jan 29, 2024
ca36fd6
DQB-27 Remove bad fixture, update get first
jplhanna Jan 31, 2024
bba7fea
DQB-27 Fix integration tests by fixing event loop creation
jplhanna Feb 3, 2024
ddb6d35
DQB-27 Update sqlalchemy and pytest versioning
jplhanna Feb 3, 2024
02b5184
DQB-27 Fix pydantic config not properly dumping db uri
jplhanna Feb 3, 2024
14edaab
DQB-27 Align tests with actual run of bot
jplhanna Feb 3, 2024
f3295b5
DQB-27 Remove unnecessary mypy workaround
jplhanna Feb 5, 2024
8249871
DQB-27 Introduce menu tables and update alembic for sqlmodel
jplhanna Feb 6, 2024
628a074
DQB-27 Update ignore files
jplhanna Feb 6, 2024
72a74bd
DQB-27 Update tavern group to add more layers
jplhanna Feb 6, 2024
e800aff
DQB-27 Introduce code behind add menu item
jplhanna Feb 6, 2024
83153ac
DQB-27 Fix menu lookup query
jplhanna Feb 6, 2024
9fb1974
DQB-27 Update group commands and clean up menu format
jplhanna Feb 6, 2024
e8aa13a
DQB-27 Create unit tests for upsert controller
jplhanna Feb 7, 2024
ce6b69f
DQB-27 Introduce new integration tests
jplhanna Feb 7, 2024
dc3914d
DQB-27 Update more of query arg to remove type in name
jplhanna Feb 7, 2024
69c81d9
DQB-27 Update ruff config to support new style
jplhanna Feb 7, 2024
d813095
DQB-27 Update service code to support multiple repos
jplhanna Feb 7, 2024
728bba0
DQB-27 Create tests for remove item
jplhanna Feb 7, 2024
1c6ac3b
DQB-27 Create more tests for deleting a menu item
jplhanna Feb 7, 2024
df4bbf9
Merge branch 'main' into DQB-27-create-weekly-menu
jplhanna Feb 8, 2024
7cae7a9
DQB-27 Fix typo in docker ignore
jplhanna Feb 8, 2024
f75a2de
DQB-27 Update github actions
jplhanna Feb 8, 2024
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
5 changes: 2 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.github
.mypy_cache
.pytest_cache
alembic
alembic.ini
logs
logsd
jplhanna marked this conversation as resolved.
Show resolved Hide resolved
local.env
.gitignore
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.10'
python-version: '3.11'
- name: Build Docker images
run: |
docker-compose build test-pipeline
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage.xml
local.env
docker-compose.override.yml
.env
.dmypy.json
77 changes: 77 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
### GENERAL CONFIG ###
[general]
# Ignore rules, reference them by id or name (comma-separated)
ignore=title-trailing-punctuation, T3

# verbosity should be a value between 1 and 3
verbosity = 2

# By default gitlint will ignore certain commits
ignore-merge-commits=true
ignore-revert-commits=true
ignore-fixup-commits=true
ignore-fixup-amend-commits=true
ignore-squash-commits=true

# Ignore any data sent to gitlint via stdin
ignore-stdin=true

# Fetch additional meta-data from the local repository when manually passing a
# commit message to gitlint via stdin or --commit-msg. Disabled by default.
staged=true

# Hard fail when the target commit range is empty.
fail-without-commits=true

# Whether to use Python `search` instead of `match` semantics in rules
regex-style-search=true

### RULE CONFIGURATION ###
[title-max-length]
line-length=100

[title-min-length]
min-length=5

[title-must-not-contain-word]
# Comma-separated list of words that should not occur in
# the commit message title (case-insensitive).
words=wip,foobar

[title-match-regex]
regex=^DQB-\d+\s.*

[body-max-line-length]
line-length=120

[body-min-length]
min-length=5

[body-changed-file-mention]
# Files that need to be explicitly mentioned in the body when they change
files=gitlint-core/gitlint/rules.py,README.md,pyproject.toml,pre-commit-config.yaml,Dockerfile,docker-compose.yaml


### NAMED RULES ###
[title-must-not-contain-word:Additional-Words]
words=foo,bar


### IGNORE RULES CONFIGURATION ###
[ignore-by-title]
# Ignore rules for commits of which the title matches a regex
regex=^Release(.*) #
ignore=T1,body-min-length #

[ignore-by-body]
# Ignore rules for commits of which the body has a line that matches a regex
regex=(.*)release(.*) #
ignore=T1,body-min-length

[ignore-body-lines]
# Ignore all lines that start with 'Co-Authored-By'
regex=^Co-Authored-By #

[ignore-by-author-name]
regex=(.*)dependabot(.*) #
ignore=T1,body-min-length
18 changes: 13 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
default_install_hook_types:
- pre-commit
- prepare-commit-msg
- commit-msg
default_stages:
- pre-commit
Expand All @@ -14,7 +15,7 @@ repos:
args: [ --line-length=120 ]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.10.0
rev: v2.12.0
hooks:
- id: pretty-format-toml
args: [--autofix]
Expand All @@ -25,7 +26,7 @@ repos:
- id: check-poetry

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
Expand Down Expand Up @@ -66,9 +67,16 @@ repos:
exclude: alembic|test_.*|conftest.py
args: [ -c, pyproject.toml ]

- repo: https://github.com/milin/giticket
rev: v1.4
- repo: https://github.com/radix-ai/auto-smart-commit
rev: v1.0.3
hooks:
- id: giticket
- id: auto-smart-commit
stages:
- prepare-commit-msg

- repo: https://github.com/jorisroovers/gitlint
rev: v0.19.1
hooks:
- id: gitlint
stages:
- commit-msg
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ENV PATH="$POETRY_VIRTUALENVS_PATH/bin:$PIPX_BIN_DIR:$PATH"
RUN pip install --upgrade pip \
&& pip install pipx \
&& pipx install poetry==$POETRY_VERSION
RUN apt-get update && apt-get install -y --no-install-recommends gcc

# Install python dependencies
RUN poetry install --no-root --no-ansi --no-interaction --only=main --no-directory
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DISCORD_ACCOUNT_TOKEN="account token for you discord bot"
DATABASE_NAME="Name for the database"
DATABASE_USER="Name for user with access to the database"
DATABASE_PASSWORD="Password to the database"
DISCORD_OWNER_ID="The discord id of the owner of the channel you are using."
```

Install all packages and start the server using `Docker` and `docker-compose`
Expand Down
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
hooks = black
black.type = console_scripts
black.entrypoint = black
black.options = -l 79 REVISION_SCRIPT_FILENAME
black.options = -l 120 REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
Expand Down
6 changes: 4 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
from src.config import DATABASE_URI
from src.config import DBSettings
from src.helpers.sqlalchemy_helpers import BaseModel
from src import model_hub

config = context.config
db_settings = DBSettings()

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name) # type: ignore

config.set_main_option("sqlalchemy.url", DATABASE_URI)
config.set_main_option("sqlalchemy.url", db_settings.database_uri)

# add your model's MetaData object here
# for 'autogenerate' support
Expand Down
1 change: 1 addition & 0 deletions alembic/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
${imports if imports else ""}

# revision identifiers, used by Alembic.
Expand Down
59 changes: 59 additions & 0 deletions alembic/versions/4232a8d67776_introduce_menu_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Introduce menu tables

Revision ID: 4232a8d67776
Revises: 2f0c6e712786
Create Date: 2024-02-06 02:34:23.627469

"""

from alembic import op
import sqlalchemy as sa
import sqlmodel

from src.constants import DayOfWeek
from src.helpers.sqlalchemy_helpers import EnumColumn

# revision identifiers, used by Alembic.
revision = "4232a8d67776"
down_revision = "2f0c6e712786"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"menu",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("datetime_created", sa.DateTime(), nullable=False),
sa.Column("datetime_edited", sa.DateTime(), nullable=False),
sa.Column("server_id", sa.Integer(), nullable=False),
sa.Column("start_date", sa.Date(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"menu_item",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("datetime_created", sa.DateTime(), nullable=False),
sa.Column("datetime_edited", sa.DateTime(), nullable=False),
sa.Column("food", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("day_of_the_week", EnumColumn(DayOfWeek), nullable=True),
sa.Column("menu_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["menu_id"],
["menu.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.drop_constraint("user_quest_quest_id_fkey", "user_quest", type_="foreignkey")
op.create_foreign_key(None, "user_quest", "quest", ["quest_id"], ["id"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "user_quest", type_="foreignkey")
op.create_foreign_key("user_quest_quest_id_fkey", "user_quest", "quest", ["quest_id"], ["id"], ondelete="CASCADE")
op.drop_table("menu_item")
op.drop_table("menu")
# ### end Alembic commands ###
30 changes: 30 additions & 0 deletions alembic/versions/9deebb8552c0_update_server_id_to_big_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Update server id to big int

Revision ID: 9deebb8552c0
Revises: 4232a8d67776
Create Date: 2024-02-06 06:16:05.689061

"""

from alembic import op
import sqlalchemy as sa
import sqlmodel


# revision identifiers, used by Alembic.
revision = "9deebb8552c0"
down_revision = "4232a8d67776"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column("menu", "server_id", existing_type=sa.INTEGER(), type_=sa.BigInteger(), existing_nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column("menu", "server_id", existing_type=sa.BigInteger(), type_=sa.INTEGER(), existing_nullable=False)
# ### end Alembic commands ###
44 changes: 26 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
version: "3.7"
x-common-variables: &common-variables
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USER: ${DATABASE_USER}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}

x-common-db-variables: &common-db-variables
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}

services:
backend:
container_name: backend-${IMAGE_TAG-latest}
image: discord_bot/backend:${IMAGE_TAG-latest}
environment:
<<: *common-variables
DISCORD_ACCOUNT_TOKEN: ${DISCORD_ACCOUNT_TOKEN}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USER: ${DATABASE_USER}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_HOST: 'postgres'
DISCORD_OWNER_ID: ${DISCORD_OWNER_ID}
volumes:
Expand All @@ -29,39 +36,40 @@ services:
command: [ "postgres", "-c", "listen_addresses=*", "-c", "log_statement=all" ]
restart: always
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
<<: *common-db-variables
POSTGRES_DB: ${DATABASE_NAME}
PGDATA: /var/lib/postgresql/data
networks:
- network
ports:
- "5432:5432"
expose:
- "5432"
volumes:
- db:/var/lib/postgresql/data

test-db:
image: postgres:14
hostname: "test_db"
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
<<: *common-db-variables
POSTGRES_DB: ${TEST_DATABASE_NAME}
ports:
- "5433:5432"
networks:
- network

test-pipeline:
container_name: test-pipeline-${IMAGE_TAG-latest}
image: discord_bot/test_pipeline:${IMAGE_TAG-latest}
environment:
DATABASE_HOST: 'test-db'
TEST_DATABASE_NAME: ${TEST_DATABASE_NAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
TEST_DATABASE_PORT: '5432'
DATABASE_USER: ${DATABASE_USER}
<<: *common-variables
DATABASE_HOST: 'test_db'
DATABASE_NAME: ${TEST_DATABASE_NAME}
DATABASE_PORT: '5432'
DISCORD_ACCOUNT_TOKEN: "fake_token"
LOGGER__HANDLERS__BASIC_HANDLER__HANDLER_CLASS: 'logging.StreamHandler'
LOGGER__HANDLERS__BASIC_HANDLER__LEVEL: 20
LOGGER__HANDLERS__BASIC_HANDLER__FORMATTER: 'simple_formatter'
LOGGER__HANDLERS__BASIC_HANDLER__STREAM: 'ext://sys.stdout'
volumes:
- .:/app
networks:
- network
build:
context: .
dockerfile: Dockerfile
Expand Down
Loading
Loading