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

Migrate db to sqlalchemy #83

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

EduKav1813
Copy link
Collaborator

@EduKav1813 EduKav1813 commented Nov 5, 2024

The goal of this PR is to migrate from <Flask + peewee> to <Flask + SQLAlchemy> stack. The migration is also followed by a partial refactoring on the MVP patter (sort of), but without a presenter right now.

While I tested the setup manually, I would like to write more tests to simplify validation. Right now the PR is in the Draft phase.

Another thing is that I implemented a BitField type, and after testing I realized that it may be a misuse/overkill. It supports multiple flags, where each bit is a flag. In the current version of the application we need it to store the anonymity, which might be better implemented via Enum or something. I am not sure if we would need this BitField in the future. Please let me know in the comments.

P.S: I will also check for missing type hints and docstrings (I have to write many) later.

Changes:
- Removing pyparsing (3.0.7)
- Updating packaging (21.3 -> 24.1)
- Updating gunicorn (21.2.0 -> 23.0.0)
- Updating psycopg2-binary (2.9.9 -> 2.9.10)
- Updating pysqlite3 (0.5.3 -> 0.5.4)
- Updating pytz (2024.1 -> 2024.2)

Signed-off-by: Eduard Kaverinskyi <[email protected]>
Signed-off-by: Eduard Kaverinskyi <[email protected]>
Signed-off-by: Eduard Kaverinskyi <[email protected]>
@EduKav1813 EduKav1813 self-assigned this Nov 5, 2024
whois/web.py Outdated
Comment on lines 95 to 96
devices = device_repository.get_all()
recent = filter_recent(timedelta(**settings.recent_time), devices)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep get_recent in device_repository

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the DeviceRepository: ce1ef8e

whois/web.py Outdated
visible_devices = filter_hidden(recent)
users = filter_hidden(owners_from_devices(visible_devices))

if current_user.is_authenticated:
unclaimed = unclaimed_devices(recent)
mine = current_user.devices
mine = filter(lambda device: device.owner == current_user.get_id(), devices)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it this not possible to keep this logic within current_user

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it's fully possible like the old way, but as a compromise I implemented this fetch in the DeviceRepository, where we pass the current_user.get_id()

1c1cfdc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this file needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file indeed was not used at the moment and removed. I t was planned to have multiple configurations for the app. This functionality was implemented here -> 32d9f54

@EduKav1813 EduKav1813 marked this pull request as ready for review November 12, 2024 20:34
@EduKav1813 EduKav1813 requested a review from not7cd November 12, 2024 20:34
@EduKav1813
Copy link
Collaborator Author

@not7cd I implemented everything I wanted in this PR, and I think it is ready for review. To not grow this PR any further I would focus on testing and merging this, and to implement/move any other functionality in separate PR's/issues

@EduKav1813
Copy link
Collaborator Author

@not7cd Additionally, since you are much more experienced with Mikrotik, I would like to ask you to review the structure of the settings templates: whois/settings/settings_template.py. I suspect that there may be some settings in one class that may belong to the other, and while it does not makes significant practical difference, organizing them properly would help people with less domain knowledge on this matter.

@EduKav1813 EduKav1813 requested a review from oneacik November 30, 2024 17:54
@EduKav1813
Copy link
Collaborator Author

@oneacik As we agreed, added you as a reviewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants