batch upload impl

This commit is contained in:
jay brown
2025-08-06 15:06:18 -07:00
parent fac5615c15
commit 7014fa790b
17 changed files with 1272 additions and 97 deletions
+133 -2
View File
@@ -96,6 +96,61 @@ func (q *Queries) CreateBatchUpload(ctx context.Context, arg *CreateBatchUploadP
return id, err
}
const createBatchUploadWithStorage = `-- name: CreateBatchUploadWithStorage :one
INSERT INTO batch_uploads (
client_id,
original_filename,
total_documents,
status,
archive_bucket,
archive_key,
file_size_bytes
) VALUES ($1, $2, $3, $4::batch_status, $5, $6, $7)
RETURNING id, created_at
`
type CreateBatchUploadWithStorageParams struct {
ClientID string `db:"client_id"`
OriginalFilename string `db:"original_filename"`
TotalDocuments int32 `db:"total_documents"`
Column4 BatchStatus `db:"column_4"`
ArchiveBucket *string `db:"archive_bucket"`
ArchiveKey *string `db:"archive_key"`
FileSizeBytes *int64 `db:"file_size_bytes"`
}
type CreateBatchUploadWithStorageRow struct {
ID uuid.UUID `db:"id"`
CreatedAt pgtype.Timestamp `db:"created_at"`
}
// CreateBatchUploadWithStorage
//
// INSERT INTO batch_uploads (
// client_id,
// original_filename,
// total_documents,
// status,
// archive_bucket,
// archive_key,
// file_size_bytes
// ) VALUES ($1, $2, $3, $4::batch_status, $5, $6, $7)
// RETURNING id, created_at
func (q *Queries) CreateBatchUploadWithStorage(ctx context.Context, arg *CreateBatchUploadWithStorageParams) (*CreateBatchUploadWithStorageRow, error) {
row := q.db.QueryRow(ctx, createBatchUploadWithStorage,
arg.ClientID,
arg.OriginalFilename,
arg.TotalDocuments,
arg.Column4,
arg.ArchiveBucket,
arg.ArchiveKey,
arg.FileSizeBytes,
)
var i CreateBatchUploadWithStorageRow
err := row.Scan(&i.ID, &i.CreatedAt)
return &i, err
}
const getBatchUpload = `-- name: GetBatchUpload :one
SELECT id, client_id, original_filename, total_documents, processed_documents,
failed_documents, invalid_type_documents, status, progress_percent,
@@ -109,6 +164,21 @@ type GetBatchUploadParams struct {
ClientID string `db:"client_id"`
}
type GetBatchUploadRow struct {
ID uuid.UUID `db:"id"`
ClientID string `db:"client_id"`
OriginalFilename string `db:"original_filename"`
TotalDocuments int32 `db:"total_documents"`
ProcessedDocuments int32 `db:"processed_documents"`
FailedDocuments int32 `db:"failed_documents"`
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
Status BatchStatus `db:"status"`
ProgressPercent int32 `db:"progress_percent"`
FailedFilenames []byte `db:"failed_filenames"`
CreatedAt pgtype.Timestamp `db:"created_at"`
CompletedAt pgtype.Timestamp `db:"completed_at"`
}
// GetBatchUpload
//
// SELECT id, client_id, original_filename, total_documents, processed_documents,
@@ -116,9 +186,9 @@ type GetBatchUploadParams struct {
// failed_filenames, created_at, completed_at
// FROM batch_uploads
// WHERE id = $1 AND client_id = $2
func (q *Queries) GetBatchUpload(ctx context.Context, arg *GetBatchUploadParams) (*BatchUpload, error) {
func (q *Queries) GetBatchUpload(ctx context.Context, arg *GetBatchUploadParams) (*GetBatchUploadRow, error) {
row := q.db.QueryRow(ctx, getBatchUpload, arg.ID, arg.ClientID)
var i BatchUpload
var i GetBatchUploadRow
err := row.Scan(
&i.ID,
&i.ClientID,
@@ -136,6 +206,67 @@ func (q *Queries) GetBatchUpload(ctx context.Context, arg *GetBatchUploadParams)
return &i, err
}
const getBatchUploadWithStorage = `-- name: GetBatchUploadWithStorage :one
SELECT id, client_id, original_filename, total_documents,
processed_documents, failed_documents, invalid_type_documents,
status, archive_bucket, archive_key, file_size_bytes,
failed_filenames, created_at, completed_at
FROM batch_uploads
WHERE id = $1 AND client_id = $2
`
type GetBatchUploadWithStorageParams struct {
ID uuid.UUID `db:"id"`
ClientID string `db:"client_id"`
}
type GetBatchUploadWithStorageRow struct {
ID uuid.UUID `db:"id"`
ClientID string `db:"client_id"`
OriginalFilename string `db:"original_filename"`
TotalDocuments int32 `db:"total_documents"`
ProcessedDocuments int32 `db:"processed_documents"`
FailedDocuments int32 `db:"failed_documents"`
InvalidTypeDocuments int32 `db:"invalid_type_documents"`
Status BatchStatus `db:"status"`
ArchiveBucket *string `db:"archive_bucket"`
ArchiveKey *string `db:"archive_key"`
FileSizeBytes *int64 `db:"file_size_bytes"`
FailedFilenames []byte `db:"failed_filenames"`
CreatedAt pgtype.Timestamp `db:"created_at"`
CompletedAt pgtype.Timestamp `db:"completed_at"`
}
// GetBatchUploadWithStorage
//
// SELECT id, client_id, original_filename, total_documents,
// processed_documents, failed_documents, invalid_type_documents,
// status, archive_bucket, archive_key, file_size_bytes,
// failed_filenames, created_at, completed_at
// FROM batch_uploads
// WHERE id = $1 AND client_id = $2
func (q *Queries) GetBatchUploadWithStorage(ctx context.Context, arg *GetBatchUploadWithStorageParams) (*GetBatchUploadWithStorageRow, error) {
row := q.db.QueryRow(ctx, getBatchUploadWithStorage, arg.ID, arg.ClientID)
var i GetBatchUploadWithStorageRow
err := row.Scan(
&i.ID,
&i.ClientID,
&i.OriginalFilename,
&i.TotalDocuments,
&i.ProcessedDocuments,
&i.FailedDocuments,
&i.InvalidTypeDocuments,
&i.Status,
&i.ArchiveBucket,
&i.ArchiveKey,
&i.FileSizeBytes,
&i.FailedFilenames,
&i.CreatedAt,
&i.CompletedAt,
)
return &i, err
}
const getDocumentsByBatchId = `-- name: GetDocumentsByBatchId :many
SELECT id, clientId, hash
FROM documents
+3
View File
@@ -245,6 +245,9 @@ type BatchUpload struct {
FailedFilenames []byte `db:"failed_filenames"`
CreatedAt pgtype.Timestamp `db:"created_at"`
CompletedAt pgtype.Timestamp `db:"completed_at"`
ArchiveBucket *string `db:"archive_bucket"`
ArchiveKey *string `db:"archive_key"`
FileSizeBytes *int64 `db:"file_size_bytes"`
}
type Client struct {