Skip to content

Commit

Permalink
Merge branch 'main' into users
Browse files Browse the repository at this point in the history
  • Loading branch information
samu9 committed Feb 21, 2025
2 parents fec6a99 + 3546199 commit 4a7e510
Show file tree
Hide file tree
Showing 73 changed files with 698 additions and 1,016 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: mirromutth/mysql-action@v1.1
with:
mysql database: "hermadata_test" # Optional, default value is "test". The specified database which will be create
mysql root password: "dev"
- name: Set up Python
# This is the version of the action for setting up Python, not the Python version.
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: "3.x"
# Optional - x64 or x86 architecture, defaults to x64
architecture: "x64"
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install .
pip install pytest httpx pytest-env pytest-dotenv
- name: Database migrations
run: |
cd backend
alembic -c tests/alembic.ini upgrade head
- name: Run tests
run: |
cd backend
mkdir tests/storage
pytest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.venv
__pycache__
.env
backend/.*.env
frontend/.env
backend/attic
backend/tests/storage
uv.lock

# Logs
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Test badge](https://github.com/samu9/hermadata/actions/workflows/test.yml/badge.svg)

# Hermadata
A management application for animal shelters.

Expand All @@ -16,4 +18,4 @@ It is composed of a [Backend](#Backend) and a [Frontend](#Frontend) part.
### Technologies
* Typescript
* React
* Tailwind
* Tailwind
3 changes: 2 additions & 1 deletion backend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"jinja": true,
"justMyCode": false,
"env": {
"AWS_PROFILE": "hermadata"
"AWS_PROFILE": "hermadata",
"ENV_PATH": ".dev.env"
}
}
]
Expand Down
7 changes: 7 additions & 0 deletions backend/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.9.0

# IMPROVEMENTS:

- use ruff
- enforce uppercase name, surname, fiscalcode in `NewAdopterModel`

# 0.8.2

# FIXES:
Expand Down
2 changes: 1 addition & 1 deletion backend/hermadata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Hermadata backend"""

__version__ = "0.8.2"
__version__ = "0.9.0"
6 changes: 3 additions & 3 deletions backend/hermadata/database/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context
from sqlalchemy import engine_from_config, pool

from hermadata.database.alembic.import_initial_data import import_doc_kinds

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
22 changes: 7 additions & 15 deletions backend/hermadata/database/alembic/import_initial_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import csv
import os

from sqlalchemy import Engine, insert, select, update
from sqlalchemy.orm import sessionmaker

from hermadata.database.models import Comune, DocumentKind, Provincia, Race

INITIAL_DATA_DIR = os.path.join(os.path.dirname(__file__), "initial_data")
Expand All @@ -13,11 +15,7 @@ def import_comuni_and_province(engine: Engine):
with open(os.path.join(INITIAL_DATA_DIR, "province.csv"), "r") as fp:
reader = csv.DictReader(fp, delimiter=";")
for r in reader:
check = s.execute(
select(Provincia.id).where(
Provincia.id == r["sigla_provincia"]
)
).first()
check = s.execute(select(Provincia.id).where(Provincia.id == r["sigla_provincia"])).first()
if check:
continue
s.execute(
Expand All @@ -30,9 +28,7 @@ def import_comuni_and_province(engine: Engine):
with open(os.path.join(INITIAL_DATA_DIR, "comuni.csv"), "r") as fp:
reader = csv.DictReader(fp, delimiter=";")
for r in reader:
check = s.execute(
select(Comune.id).where(Comune.id == r["codice_belfiore"])
).first()
check = s.execute(select(Comune.id).where(Comune.id == r["codice_belfiore"])).first()
if check:
continue
s.execute(
Expand All @@ -49,10 +45,8 @@ def import_races(engine: Engine):
with Session.begin() as s:
with open(os.path.join(INITIAL_DATA_DIR, "races.csv"), "r") as fp:
reader = csv.DictReader(fp)
for i, r in enumerate(reader):
check = s.execute(
select(Race.id).where(Race.id == r["id"])
).first()
for _, r in enumerate(reader):
check = s.execute(select(Race.id).where(Race.id == r["id"])).first()
if check:
continue
s.execute(
Expand All @@ -77,9 +71,7 @@ def import_doc_kinds(engine: Engine | None = None):
code, name, uploadable, rendered = r
uploadable = int(uploadable)
rendered = int(rendered)
check = s.execute(
select(DocumentKind.id).where(DocumentKind.code == code)
).first()
check = s.execute(select(DocumentKind.id).where(DocumentKind.code == code)).first()
if check:
s.execute(
update(DocumentKind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from hermadata.database.alembic.import_initial_data import import_doc_kinds

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "12a20b0bf3d3"
Expand All @@ -25,18 +22,13 @@ def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"document_kind",
sa.Column(
"uploadable", sa.Boolean(), nullable=False, server_default=sa.true()
),
sa.Column("uploadable", sa.Boolean(), nullable=False, server_default=sa.true()),
)
op.add_column(
"document_kind",
sa.Column(
"rendered", sa.Boolean(), nullable=False, server_default=sa.true()
),
sa.Column("rendered", sa.Boolean(), nullable=False, server_default=sa.true()),
)
# ### end Alembic commands ###
import_doc_kinds(op.get_bind())


def downgrade() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
Create Date: 2023-11-24 23:23:14.368436
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op

from hermadata.database.alembic.import_initial_data import import_races


# revision identifiers, used by Alembic.
revision: str = "1bb12e9dcab1"
down_revision: Union[str, None] = "3bebd7731267"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql

from hermadata.database.models import DocumentKind

# revision identifiers, used by Alembic.
revision: str = "368a2d2d72fd"
down_revision: Union[str, None] = "bd1383d9f555"
Expand All @@ -33,6 +35,7 @@ def upgrade() -> None:

def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.get_bind().execute(sa.delete(DocumentKind))
op.alter_column(
"document_kind",
"code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "38979c9ad66f"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
Create Date: 2023-11-24 23:20:22.007586
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op

from hermadata.database.alembic.import_initial_data import (
import_comuni_and_province,
)


# revision identifiers, used by Alembic.
revision: str = "3bebd7731267"
down_revision: Union[str, None] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "60bd24dc572c"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "73044398fda6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -55,28 +55,18 @@ def downgrade() -> None:
"medical_record",
sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
sa.Column("causal", mysql.VARCHAR(length=100), nullable=False),
sa.Column(
"price", mysql.DECIMAL(precision=15, scale=2), nullable=False
),
sa.Column(
"vet_id", mysql.INTEGER(), autoincrement=False, nullable=False
),
sa.Column(
"animal_id", mysql.INTEGER(), autoincrement=False, nullable=False
),
sa.Column("price", mysql.DECIMAL(precision=15, scale=2), nullable=False),
sa.Column("vet_id", mysql.INTEGER(), autoincrement=False, nullable=False),
sa.Column("animal_id", mysql.INTEGER(), autoincrement=False, nullable=False),
sa.Column("performed_at", sa.DATE(), nullable=False),
sa.Column(
"created_at",
mysql.DATETIME(),
server_default=sa.text("CURRENT_TIMESTAMP"),
nullable=False,
),
sa.ForeignKeyConstraint(
["animal_id"], ["animal.id"], name="medical_record_ibfk_1"
),
sa.ForeignKeyConstraint(
["vet_id"], ["vet.id"], name="medical_record_ibfk_2"
),
sa.ForeignKeyConstraint(["animal_id"], ["animal.id"], name="medical_record_ibfk_1"),
sa.ForeignKeyConstraint(["vet_id"], ["vet.id"], name="medical_record_ibfk_2"),
sa.PrimaryKeyConstraint("id"),
mysql_collate="utf8mb4_0900_ai_ci",
mysql_default_charset="utf8mb4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "bd1383d9f555"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
Expand All @@ -21,25 +21,17 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"vet", sa.Column("name", sa.String(length=100), nullable=True)
)
op.add_column(
"vet", sa.Column("surname", sa.String(length=100), nullable=True)
)
op.add_column("vet", sa.Column("name", sa.String(length=100), nullable=True))
op.add_column("vet", sa.Column("surname", sa.String(length=100), nullable=True))
op.drop_column("vet", "cognome")
op.drop_column("vet", "nome")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"vet", sa.Column("nome", mysql.VARCHAR(length=100), nullable=True)
)
op.add_column(
"vet", sa.Column("cognome", mysql.VARCHAR(length=100), nullable=True)
)
op.add_column("vet", sa.Column("nome", mysql.VARCHAR(length=100), nullable=True))
op.add_column("vet", sa.Column("cognome", mysql.VARCHAR(length=100), nullable=True))
op.drop_column("vet", "surname")
op.drop_column("vet", "name")
# ### end Alembic commands ###
Loading

0 comments on commit 4a7e510

Please sign in to comment.