Merged in feature/add-deletes (pull request #214)
support delete for client, document and folder * support delete for client, document and folder * remove batch cancel conflict not used Approved-by: Jacob Mathison
This commit is contained in:
@@ -64,6 +64,39 @@ func (q *Queries) AddDocumentUpload(ctx context.Context, arg *AddDocumentUploadP
|
||||
return err
|
||||
}
|
||||
|
||||
const collectDocumentS3Paths = `-- name: CollectDocumentS3Paths :many
|
||||
SELECT de.bucket, de.key FROM documentEntries de WHERE de.documentId = $1
|
||||
`
|
||||
|
||||
type CollectDocumentS3PathsRow struct {
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Collect S3 bucket+key from documentEntries before deleting, for logging orphaned S3 objects
|
||||
//
|
||||
// SELECT de.bucket, de.key FROM documentEntries de WHERE de.documentId = $1
|
||||
func (q *Queries) CollectDocumentS3Paths(ctx context.Context, documentID uuid.UUID) ([]*CollectDocumentS3PathsRow, error) {
|
||||
rows, err := q.db.Query(ctx, collectDocumentS3Paths, documentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*CollectDocumentS3PathsRow{}
|
||||
for rows.Next() {
|
||||
var i CollectDocumentS3PathsRow
|
||||
if err := rows.Scan(&i.Bucket, &i.Key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, &i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const createDocument = `-- name: CreateDocument :one
|
||||
INSERT INTO documents (clientId, hash, batch_id, filename, folderId, originalPath, file_size_bytes) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id
|
||||
`
|
||||
@@ -96,6 +129,98 @@ func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const deleteDocumentCleanEntries = `-- name: DeleteDocumentCleanEntries :exec
|
||||
DELETE FROM documentCleanEntries
|
||||
WHERE cleanId IN (
|
||||
SELECT id FROM documentCleans WHERE documentId = $1
|
||||
)
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete clean entries for all cleans belonging to this document
|
||||
//
|
||||
// DELETE FROM documentCleanEntries
|
||||
// WHERE cleanId IN (
|
||||
// SELECT id FROM documentCleans WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) DeleteDocumentCleanEntries(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentCleanEntries, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentCleans = `-- name: DeleteDocumentCleans :exec
|
||||
DELETE FROM documentCleans WHERE documentId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete clean records for this document
|
||||
//
|
||||
// DELETE FROM documentCleans WHERE documentId = $1
|
||||
func (q *Queries) DeleteDocumentCleans(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentCleans, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentEntries = `-- name: DeleteDocumentEntries :exec
|
||||
DELETE FROM documentEntries WHERE documentId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete S3 entry records for this document
|
||||
//
|
||||
// DELETE FROM documentEntries WHERE documentId = $1
|
||||
func (q *Queries) DeleteDocumentEntries(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentEntries, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentFieldExtractionArrayFields = `-- name: DeleteDocumentFieldExtractionArrayFields :exec
|
||||
DELETE FROM documentFieldExtractionArrayFields
|
||||
WHERE fieldExtractionId IN (
|
||||
SELECT id FROM documentFieldExtractions WHERE documentId = $1
|
||||
)
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete array fields for all field extractions belonging to this document
|
||||
//
|
||||
// DELETE FROM documentFieldExtractionArrayFields
|
||||
// WHERE fieldExtractionId IN (
|
||||
// SELECT id FROM documentFieldExtractions WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) DeleteDocumentFieldExtractionArrayFields(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentFieldExtractionArrayFields, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentFieldExtractionVersions = `-- name: DeleteDocumentFieldExtractionVersions :exec
|
||||
DELETE FROM documentFieldExtractionVersions
|
||||
WHERE documentId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete version entries for all field extractions belonging to this document
|
||||
//
|
||||
// DELETE FROM documentFieldExtractionVersions
|
||||
// WHERE documentId = $1
|
||||
func (q *Queries) DeleteDocumentFieldExtractionVersions(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentFieldExtractionVersions, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentFieldExtractions = `-- name: DeleteDocumentFieldExtractions :exec
|
||||
DELETE FROM documentFieldExtractions WHERE documentId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete field extraction records for this document
|
||||
//
|
||||
// DELETE FROM documentFieldExtractions WHERE documentId = $1
|
||||
func (q *Queries) DeleteDocumentFieldExtractions(ctx context.Context, documentID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentFieldExtractions, documentID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getDocumentEnriched = `-- name: GetDocumentEnriched :one
|
||||
SELECT
|
||||
d.id,
|
||||
@@ -334,6 +459,23 @@ func (q *Queries) GetDocumentUploadCurrentPart(ctx context.Context, arg *GetDocu
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const hardDeleteDocument = `-- name: HardDeleteDocument :execrows
|
||||
DELETE FROM documents WHERE id = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Hard delete the document row itself. Returns the number of rows deleted (0 or 1).
|
||||
// documentLabels are removed automatically via ON DELETE CASCADE.
|
||||
//
|
||||
// DELETE FROM documents WHERE id = $1
|
||||
func (q *Queries) HardDeleteDocument(ctx context.Context, documentID uuid.UUID) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, hardDeleteDocument, documentID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const listDocumentIDsBatch = `-- name: ListDocumentIDsBatch :many
|
||||
SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user