Migrate from Prisma Python to Piccolo#190
Conversation
Wow, this touches a lot of files. I got Amp to do the work for me: https://ampcode.com/threads/T-019d9fa2-e030-75c8-b4b2-cbd87256dc95
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
* Add Beest (hackclub#190) * Fix [transcripts]: grammar correction Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update nephthys/transcripts/transcripts/beest.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update nephthys/transcripts/transcripts/beest.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update nephthys/transcripts/transcripts/beest.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates Nephthys from the unmaintained Prisma Python client to the Piccolo ORM, introducing a Piccolo-backed schema plus a migration workflow and updating all DB access paths accordingly.
Changes:
- Replace Prisma dependency and schema with Piccolo tables + configuration.
- Update DB queries across actions/events/tasks/views/macros to use Piccolo’s async APIs and snake_case fields.
- Add Piccolo migrations and container startup wiring to run migrations on boot.
Reviewed changes
Copilot reviewed 64 out of 66 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Swap Prisma dependency for Piccolo (Postgres + uvloop extras). |
| prisma/schema.prisma | Remove legacy Prisma schema. |
| piccolo_conf.py | Add Piccolo engine + app registry configuration. |
| nephthys/piccolo_app.py | Register Piccolo app config (tables + migrations folder). |
| nephthys/piccolo_migrations/init.py | Initialize migrations package. |
| nephthys/piccolo_migrations/nephthys_010_init.py | Introduce initial SQL migration for legacy-compatible schema. |
| nephthys/piccolo_migrations/nephthys_011_timestamp_to_timestamptz.py | Convert legacy TIMESTAMP columns to TIMESTAMPTZ. |
| nephthys/piccolo_migrations/nephthys_012_snake_case_type_names.py | Rename legacy enum types to snake_case. |
| nephthys/database/enums.py | Add TicketStatus/UserType enums + Piccolo column wrappers. |
| nephthys/database/postgres_enum.py | Add custom Piccolo column factory for Postgres enums. |
| nephthys/database/tables.py | Define Piccolo table models mapping to legacy column names. |
| nephthys/main.py | Start/stop Piccolo connection pool; adjust imports/startup flow. |
| nephthys/utils/env.py | Remove Prisma client initialization from environment config. |
| nephthys/utils/starlette.py | Update health/metrics endpoints to remove Prisma health/metrics. |
| nephthys/utils/permissions.py | Switch ticket lookup for permission checks to Piccolo. |
| nephthys/utils/old_tickets.py | Port unanswered ticket query logic to Piccolo. |
| nephthys/utils/ticket_methods.py | Port bot message persistence / ticket deletes to Piccolo. |
| nephthys/utils/stats.py | Port stats calculations to Piccolo (leaderboards/counting). |
| nephthys/events/message_creation.py | Port ticket creation, thread handling, user upsert, and tag lookup to Piccolo. |
| nephthys/events/message_deletion.py | Port ticket lookup/deletion on Slack message deletion to Piccolo. |
| nephthys/events/message/send_backend_message.py | Port category tag loading + user fields to Piccolo models. |
| nephthys/events/app_home_opened.py | Port Slack user DB lookup to Piccolo. |
| nephthys/events/channel_left.py | Port helper flag update to Piccolo. |
| nephthys/views/home/dashboard.py | Update User model import to Piccolo table. |
| nephthys/views/home/stats.py | Update User model import to Piccolo table. |
| nephthys/views/home/category_tags.py | Port category tags query to Piccolo. |
| nephthys/views/home/team_tags.py | Port team tags/subscriptions view to Piccolo. |
| nephthys/views/home/assigned.py | Port assigned ticket query + field names to Piccolo. |
| nephthys/views/home/components/header.py | Update User model import to Piccolo table. |
| nephthys/views/home/components/leaderboards.py | Update Slack ID field name for leaderboard rendering. |
| nephthys/views/home/components/ticket_status_pie.py | Port ticket counts queries + enum import to Piccolo. |
| nephthys/options/team_tags.py | Port tag options provider to Piccolo. |
| nephthys/options/category_tags.py | Port category tag options provider to Piccolo. |
| nephthys/tasks/update_helpers.py | Port helper sync job to Piccolo updates/inserts. |
| nephthys/tasks/fulfillment_reminder.py | Port fulfillment reminder ticket query + tag lookups to Piccolo. |
| nephthys/tasks/daily_stats.py | Port daily stats task tag lookups + fields to Piccolo. |
| nephthys/tasks/close_stale.py | Port stale-ticket closing logic and relations to Piccolo. |
| nephthys/scripts/add_dummy_data.py | Port dummy ticket creation to Piccolo saves. |
| nephthys/api/user.py | Port per-user stats endpoint to Piccolo counts. |
| nephthys/api/tickets.py | Port tickets listing endpoint to Piccolo queries + tag loading. |
| nephthys/api/ticket.py | Port single ticket endpoint + JSON serialization to Piccolo model fields. |
| nephthys/api/stats.py | Update Slack ID field name in API payload. |
| nephthys/commands/dm_magic_link.py | Port helper permission check to Piccolo user lookup. |
| nephthys/actions/resolve.py | Port resolve action (permission checks, ticket update) to Piccolo. |
| nephthys/actions/tag_subscribe.py | Port tag subscription create/delete to Piccolo. |
| nephthys/actions/create_team_tag.py | Port team tag creation/admin check to Piccolo. |
| nephthys/actions/create_category_tag.py | Port category tag creation/admin check to Piccolo. |
| nephthys/actions/assign_team_tag.py | Port backend tag assignment + subscriber notification to Piccolo. |
| nephthys/actions/assign_category_tag.py | Port category tag assignment + backend message update to Piccolo. |
| nephthys/macros/init.py | Update macro runner to use Piccolo models/enums. |
| nephthys/macros/types.py | Adjust macro base logic for Piccolo FK/object behavior. |
| nephthys/macros/resolve.py | Port resolve macro fields to Piccolo. |
| nephthys/macros/reopen.py | Port reopen macro updates/fields to Piccolo. |
| nephthys/macros/thread.py | Port thread macro to Piccolo fields/queries. |
| nephthys/macros/team_tag.py | Port ?tag macro to Piccolo tables and fields. |
| nephthys/macros/hackatime.py | Port hackatime macro to Piccolo fields/queries. |
| nephthys/macros/shipcertqueue.py | Port ship queue macro to Piccolo fields/queries. |
| nephthys/macros/hello_world.py | Update helper Slack ID field name. |
| nephthys/macros/trigger_daily_stats.py | Update helper/ticket field names. |
| nephthys/macros/trigger_fulfillment_reminder.py | Update helper/ticket field names. |
| entrypoint.sh | Add startup migrations step (configurable via RUN_MIGRATIONS). |
| Dockerfile | Remove Prisma db push; run entrypoint script; keep healthcheck. |
| .dockerignore | Ignore dev data directory. |
| .vscode/settings.json | Remove Prisma-specific VS Code setting. |
| docs/contributing.md | Add general style guidelines and Slack channel pointer. |
Comments suppressed due to low confidence (1)
nephthys/views/home/team_tags.py:58
subsis a list of Slack IDs (subs = [u.slack_id for u in sub_users]), but later you checkuser.id not in subsand set the button text/style based on that. Sinceuser.idis an int, this condition will always be true, so the UI will always show “subscribe”. Compare againstuser.slack_idor against the integersub_user_idsinstead.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 64 out of 66 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 64 out of 66 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR gets rid of Prisma (see #120) and adopts Piccolo as our ORM.
It also adds support for database migrations so we can properly manage changes we make to the database.
TODO: Work out how and when we're going to run the DB migrations.Done!