books/backend/Books.Api/Database/Migrations/026_DocumentContentHashes.sql
Nicolaj Hartmann 1f75c5d791 Add all backend domain, commands, repositories, and tests
This commit includes all previously untracked backend files:

Domain:
- Accounts, Attachments, BankConnections, Customers
- FiscalYears, Invoices, JournalEntryDrafts
- Orders, Products, UserAccess

Commands & Handlers:
- Full CQRS command structure for all domains

Repositories:
- PostgreSQL repositories for all read models
- Bank transaction and ledger repositories

GraphQL:
- Input types, scalars, and types for all entities
- Mutations and queries

Infrastructure:
- Banking integration (Enable Banking client)
- File storage, Invoicing, Reporting, SAF-T export
- Database migrations (003-029)

Tests:
- Integration tests for GraphQL endpoints
- Domain tests
- Invoicing and reporting tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 22:19:42 +01:00

27 lines
1.3 KiB
SQL

-- Migration: 026_DocumentContentHashes
-- Description: Create table for tracking document content hashes to prevent duplicate processing
CREATE TABLE IF NOT EXISTS document_content_hashes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
company_id TEXT NOT NULL,
content_hash TEXT NOT NULL, -- SHA-256 hash of file content
original_filename TEXT NOT NULL,
attachment_id TEXT, -- Reference to attachment_read_models
draft_id TEXT, -- Reference to journal_entry_draft_read_models
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Ensure unique hash per company (same document can exist in different companies)
CONSTRAINT uq_document_hash_company UNIQUE(company_id, content_hash)
);
-- Index for fast lookups by company
CREATE INDEX IF NOT EXISTS idx_document_content_hashes_company_id
ON document_content_hashes(company_id);
-- Index for hash lookups
CREATE INDEX IF NOT EXISTS idx_document_content_hashes_content_hash
ON document_content_hashes(content_hash);
COMMENT ON TABLE document_content_hashes IS 'Tracks document content hashes to prevent duplicate processing of the same document';
COMMENT ON COLUMN document_content_hashes.content_hash IS 'SHA-256 hash of the file content';
COMMENT ON COLUMN document_content_hashes.draft_id IS 'Reference to the journal entry draft created from this document';