-
-
Notifications
You must be signed in to change notification settings - Fork 129
Remove documents table #618
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis change removes the entire concept of "Document" entities from the codebase, merging their fields (such as Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant Service
participant Repo
participant DB
participant Filesystem
Client->>API: POST /items/{id}/attachments (file, title, primary)
API->>Service: AttachmentAdd(ctx, itemID, filename, type, primary, file)
Service->>Repo: Create(ctx, itemID, {Title, Content}, type, primary)
Repo->>Filesystem: Save file (hashed path)
Filesystem-->>Repo: Success/Failure
Repo->>DB: Insert Attachment (with title, path, etc.)
DB-->>Repo: Attachment entity
Repo-->>Service: Attachment entity
Service-->>API: ItemOut (with attachments: [{title, path, ...}])
API-->>Client: Response (attachment info)
Possibly related PRs
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 36 out of 36 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
backend/internal/data/ent/group.go:51
- Ensure that the new loadedTypes array size of 6 correctly reflects the removal of the "documents" edge and that all index references in GroupEdges accessor methods have been updated to prevent off-by-one errors.
loadedTypes [6]bool
backend/internal/data/ent/attachment_query.go:376
- Verify that the updated loadedTypes array for attachments (now size 1) correctly accounts for the removal of the document edge and that related eager-loading logic is properly adjusted.
loadedTypes = [1]bool{
backend/internal/data/ent/client.go:42
- Confirm that removal of the Document client initialization does not leave any downstream dependencies unresolved and update any affected modules accordingly.
c.Document = NewDocumentClient(c.config)
Deploying homebox-docs with
|
Latest commit: |
7791d43
|
Status: | ✅ Deploy successful! |
Preview URL: | https://2455caa7.homebox-docs.pages.dev |
Branch Preview URL: | https://mk-merge-attachments-and-doc.homebox-docs.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 52 out of 55 changed files in this pull request and generated 1 comment.
Files not reviewed (3)
- backend/app/api/static/docs/swagger.json: Language not supported
- backend/app/api/static/docs/swagger.yaml: Language not supported
- backend/go.mod: Language not supported
I don't understand why the SQLite integration test fails but all the others are fine. And it's only in Github Actions, the test runs fine locally when I run it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes all document-related entities and logic, merging document data into attachments and thus simplifying the overall database design and related service logic.
- Removed document table, entity, and client, along with its associated query and mutation functions.
- Updated attachment creation, update, queries, and API endpoints to include new title, path, and primary flag for improved metadata handling.
- Adjusted tests, migrations, and build configurations to reflect the new attachment-based design.
Reviewed Changes
Copilot reviewed 59 out of 62 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
backend/internal/data/ent/document/where.go | Deleted obsolete document filtering functions. |
backend/internal/data/ent/document/document.go | Removed document entity definitions and constants. |
backend/internal/data/ent/document.go | Removed document entity and related helper methods. |
backend/internal/data/ent/client.go | Removed document client references and updated hook setup. |
backend/internal/data/ent/attachment_update.go | Added handling for title and path fields in attachment updates; removed document-related code. |
backend/internal/data/ent/attachment_query.go | Removed document edge queries and related eager-loading logic. |
backend/internal/data/ent/attachment_create.go | Updated attachment creation to set title, path and perform validation accordingly. |
backend/internal/data/ent/attachment/where.go | Introduced new predicates for title and path fields. |
backend/internal/data/ent/attachment/attachment.go | Added title and path fields to the Attachment entity; removed document edge references. |
backend/internal/core/services/service_items_attachments_test.go | Updated tests to reference attachment path instead of document path. |
backend/internal/core/services/service_items_attachments.go | Updated service methods to use the new attachment design and primary flag. |
backend/app/tools/migrations/main.go | Refactored the database driver switch-case block. |
backend/app/api/static/docs/docs.go | Updated API documentation to remove references to documents. |
backend/app/api/handlers/v1/v1_ctrl_items_attachments.go | Updated HTTP handlers to handle the new primary flag and attachment field changes. |
backend/.golangci.yml & .github/workflows/partial-backend.yaml | Updated linting and workflow versions to support current project standards. |
Files not reviewed (3)
- backend/app/api/static/docs/swagger.json: Language not supported
- backend/app/api/static/docs/swagger.yaml: Language not supported
- backend/go.mod: Language not supported
Co-authored-by: Copilot <[email protected]>
Hmmm, seems that the migration isn't working quite right |
Seems to be working better but seems to loose the attachment title |
This PR is on hold until I can get the migrations stuff sorted. It seems that we're in desperate need of a total migrations system replacement as the ent migration system frankly sucks when it's embedded into an application. Will be creating a different PR for that work. |
…nto mk/merge-attachments-and-docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
backend/app/api/main.go (1)
164-166
: Enhanced migration settings improve security and reliabilityThe addition of these three migration options strengthens the database schema creation process:
- Explicitly setting the dialect ensures compatibility between different database systems
- Enabling foreign keys helps maintain data integrity during the migration
- Using replay mode ensures consistent migration application
These settings will help address the migration issues reported in GitHub Actions. From a security perspective, enabling foreign key constraints is particularly valuable as it prevents orphaned records that could potentially lead to data integrity issues.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
backend/internal/data/migrations/postgres/atlas.sum
is excluded by!**/*.sum
📒 Files selected for processing (2)
backend/app/api/main.go
(1 hunks)backend/internal/data/migrations/postgres/20250419184104_merge_docs_attachments.sql
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/app/api/main.go (1)
backend/internal/sys/config/conf_database.go (1)
Database
(12-21)
⏰ Context from checks skipped due to timeout of 90000ms (16)
- GitHub Check: Frontend Tests / Integration Tests PGSQL 16
- GitHub Check: Frontend Tests / Integration Tests
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 3/4
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 1/4
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 4/4
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 2/4
- GitHub Check: Frontend Tests / Integration Tests PGSQL 17
- GitHub Check: Frontend Tests / Integration Tests PGSQL 15
- GitHub Check: build (linux/arm64)
- GitHub Check: build (linux/arm/v7)
- GitHub Check: build (linux/amd64)
- GitHub Check: build (linux/arm64)
- GitHub Check: build (linux/arm/v7)
- GitHub Check: build (linux/amd64)
- GitHub Check: Analyze (go)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
backend/internal/data/migrations/postgres/20250419184104_merge_docs_attachments.sql (1)
11-12
:✅ Verification successful
Verify all foreign key constraints are handled
The migration drops one constraint, but there might be other foreign keys or indexes related to the documents table.
🏁 Script executed:
#!/bin/bash # Check for any other constraints or indexes referencing the documents table echo "Checking for other potential constraints or references to documents table:" rg -A 3 "CONSTRAINT.*documents|REFERENCES.*documents|INDEX.*documents" --glob "*.sql" # Look for any code that might still expect the document relationship echo "Searching for code that might still reference documents:" rg -A 3 "document_attachments|documents" --type go --type sqlLength of output: 19664
All PostgreSQL foreign keys to “documents” are accounted for and removed
Our search confirmed that the only constraint in Postgres referencing the
documents
table is
attachments_documents_attachments
in the init migration, and it’s dropped in step 3 of your merge migration. No other SQL migrations or Go code rely on a DB-leveldocuments
relationship.• SQL migrations:
– No remainingREFERENCES "documents"
orCONSTRAINT … documents
in the Postgres folder.
• Application code:
– The hits inrepo_item_attachments.go
and tests refer to a filesystem directory named “documents,” not the DB table.Security recommendation:
Wrap the entire migration in a transaction and ensure you have a recent backup—this avoids exposing intermediate states or orphaned data if something goes wrong.
What type of PR is this?
What this PR does / why we need it:
This PR removes the documents table after merging the important bits into the attachments table. This significantly simplifies the overall design of the database and also makes it simpler for further work with attachements.
Which issue(s) this PR fixes:
Part of #265
Summary by CodeRabbit
New Features
title
andpath
fields, simplifying access and management.primary
flag can be set when adding an attachment to indicate if it is the primary attachment.soldTime
property for sale details.Improvements
Removals
Bug Fixes
Documentation
primary
andsoldTime
fields.