Skip to content
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
226 changes: 35 additions & 191 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Byte-compiled / optimized / DLL files
```
# Python
__pycache__/
*.py[codz]
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
Expand All @@ -20,204 +17,51 @@ parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/
# Virtual environments
venv/
ENV/
env/
.venv/
.env/

# Translations
*.mo
*.pot
# IDE
.vscode/
.idea/
*.swp
*.swo

# Django stuff:
# Logs
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule*
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
# Environment variables
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.env.local
*.env.*

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site
# Coverage reports
.coverage
htmlcov/
.coverage.*
.coverage.xml
coverage.xml

# mypy
# Testing
.pytest_cache/
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# Database
*.sqlite
*.db

# Streamlit
.streamlit/secrets.toml
# Alembic
alembic/versions/*.py

# Isolated development worktrees
.worktrees/
# OS
.DS_Store
Thumbs.db
```
5 changes: 1 addition & 4 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
UserHasRoleModel, # noqa: F401
)
from src.modules.todo.infrastructure.models.todo_model import TodoModel # noqa: F401
from src.modules.user.infrastructure.models.refresh_token_model import (
UserSessionModel, # noqa: F401
)
from src.modules.user.infrastructure.models.user_model import UserModel # noqa: F401
from src.modules.user.infrastructure import models as user_models # noqa: F401
from src.shared.database.model import Base

settings = get_settings()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from uuid import UUID

from sqlalchemy import Index, String, UniqueConstraint
from sqlalchemy import ForeignKey, Index, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.shared.database.mixin.timestamp import SoftDeleteMixin, TimeStampMixin
Expand All @@ -24,7 +24,10 @@ class PermissionModel(Base, TimeStampMixin, SoftDeleteMixin):
)

key: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
resource_id: Mapped[UUID] = mapped_column(nullable=False)
resource_id: Mapped[UUID] = mapped_column(
ForeignKey("authorization_resources.id"),
nullable=False,
)
resource: Mapped[str] = mapped_column(String(100), nullable=False)
action: Mapped[str] = mapped_column(String(100), nullable=False)
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from uuid import UUID

from sqlalchemy import Index, UniqueConstraint
from sqlalchemy import ForeignKey, Index, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.shared.database.model import Base
Expand All @@ -23,8 +23,11 @@ class RolePermissionModel(Base):
Index("ix_role_permissions_permission_id", "permission_id"),
)

role_id: Mapped[UUID] = mapped_column(nullable=False)
permission_id: Mapped[UUID] = mapped_column(nullable=False)
role_id: Mapped[UUID] = mapped_column(ForeignKey("roles.id"), nullable=False)
permission_id: Mapped[UUID] = mapped_column(
ForeignKey("permissions.id"),
nullable=False,
)

# Relationships
role: Mapped["RoleModel"] = relationship( # type: ignore[name-defined]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from uuid import UUID

from sqlalchemy import Index, UniqueConstraint
from sqlalchemy import ForeignKey, Index, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.modules.user.infrastructure.models.user_model import UserModel
Expand All @@ -23,8 +23,8 @@ class UserHasRoleModel(Base):
Index("ix_user_has_roles_role_id", "role_id"),
)

user_id: Mapped[UUID] = mapped_column(nullable=False)
role_id: Mapped[UUID] = mapped_column(nullable=False)
user_id: Mapped[UUID] = mapped_column(ForeignKey("users.id"), nullable=False)
role_id: Mapped[UUID] = mapped_column(ForeignKey("roles.id"), nullable=False)

# Relationships
user: Mapped["UserModel"] = relationship( # type: ignore[name-defined]
Expand Down
4 changes: 2 additions & 2 deletions src/modules/todo/infrastructure/models/todo_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid

from sqlalchemy import Boolean, String
from sqlalchemy import Boolean, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column

from src.shared.database.model import Base
Expand All @@ -13,4 +13,4 @@ class TodoModel(Base, TimeStampMixin, SoftDeleteMixin):
title: Mapped[str] = mapped_column(String(255))
description: Mapped[str | None] = mapped_column(String(500), nullable=True)
is_completed: Mapped[bool] = mapped_column(Boolean, default=False)
user_id: Mapped[uuid.UUID] = mapped_column()
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"))
8 changes: 3 additions & 5 deletions src/modules/user/infrastructure/models/refresh_token_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from uuid import UUID

from sqlalchemy import Boolean, DateTime, Index, String
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.shared.database.mixin.timestamp import SoftDeleteMixin, TimeStampMixin
Expand All @@ -23,10 +24,7 @@ class UserSessionModel(Base, TimeStampMixin, SoftDeleteMixin):
Index("ix_user_sessions_device_info", "device_info"),
)

user_id: Mapped[str] = mapped_column(
String(36), # UUID as string for FK
nullable=False,
)
user_id: Mapped[UUID] = mapped_column(ForeignKey("users.id"), nullable=False)

# Session Token (hashed for security)
refresh_token_hash: Mapped[str] = mapped_column(String(255), nullable=False)
Expand Down
9 changes: 4 additions & 5 deletions src/modules/user/infrastructure/models/user_address_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from sqlalchemy import Boolean, Index, String
from uuid import UUID

from sqlalchemy import Boolean, ForeignKey, Index, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.modules.user.infrastructure.models.user_model import UserModel
Expand All @@ -21,10 +23,7 @@ class UserAddressModel(Base, TimeStampMixin, SoftDeleteMixin):
Index("ix_user_addresses_country", "country"),
)

user_id: Mapped[str] = mapped_column(
String(36), # UUID as string for FK
nullable=False,
)
user_id: Mapped[UUID] = mapped_column(ForeignKey("users.id"), nullable=False)

# Address Label (home, billing, shipping, work, etc.)
label: Mapped[str] = mapped_column(String(100), nullable=False)
Expand Down
Loading
Loading