sse + ocr replanish
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS ocr_jobs;
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE ocr_jobs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
resource_id UUID NOT NULL REFERENCES resources(id) ON DELETE CASCADE,
|
||||
file_path TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'done', 'failed')),
|
||||
error_message TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_ocr_jobs_status ON ocr_jobs(status);
|
||||
CREATE INDEX idx_ocr_jobs_resource ON ocr_jobs(resource_id);
|
||||
@@ -12,6 +12,16 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type OcrJob struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ResourceID uuid.UUID `json:"resource_id"`
|
||||
FilePath string `json:"file_path"`
|
||||
Status string `json:"status"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type RebacRelation struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ResourceID uuid.UUID `json:"resource_id"`
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: ocr_jobs.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createOCRJob = `-- name: CreateOCRJob :one
|
||||
INSERT INTO ocr_jobs (resource_id, file_path, status)
|
||||
VALUES ($1, $2, 'pending')
|
||||
RETURNING id, resource_id, file_path, status, error_message, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateOCRJobParams struct {
|
||||
ResourceID uuid.UUID `json:"resource_id"`
|
||||
FilePath string `json:"file_path"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateOCRJob(ctx context.Context, arg CreateOCRJobParams) (OcrJob, error) {
|
||||
row := q.db.QueryRowContext(ctx, createOCRJob, arg.ResourceID, arg.FilePath)
|
||||
var i OcrJob
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.FilePath,
|
||||
&i.Status,
|
||||
&i.ErrorMessage,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteOCRJob = `-- name: DeleteOCRJob :exec
|
||||
DELETE FROM ocr_jobs
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteOCRJob(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteOCRJob, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getOCRJob = `-- name: GetOCRJob :one
|
||||
SELECT id, resource_id, file_path, status, error_message, created_at, updated_at FROM ocr_jobs
|
||||
WHERE id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOCRJob(ctx context.Context, id uuid.UUID) (OcrJob, error) {
|
||||
row := q.db.QueryRowContext(ctx, getOCRJob, id)
|
||||
var i OcrJob
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.FilePath,
|
||||
&i.Status,
|
||||
&i.ErrorMessage,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listPendingOCRJobs = `-- name: ListPendingOCRJobs :many
|
||||
SELECT id, resource_id, file_path, status, error_message, created_at, updated_at FROM ocr_jobs
|
||||
WHERE status = 'pending'
|
||||
ORDER BY created_at ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListPendingOCRJobs(ctx context.Context) ([]OcrJob, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPendingOCRJobs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []OcrJob
|
||||
for rows.Next() {
|
||||
var i OcrJob
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ResourceID,
|
||||
&i.FilePath,
|
||||
&i.Status,
|
||||
&i.ErrorMessage,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateOCRJobStatus = `-- name: UpdateOCRJobStatus :exec
|
||||
UPDATE ocr_jobs
|
||||
SET status = $1, error_message = $2, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $3
|
||||
`
|
||||
|
||||
type UpdateOCRJobStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateOCRJobStatus(ctx context.Context, arg UpdateOCRJobStatusParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateOCRJobStatus, arg.Status, arg.ErrorMessage, arg.ID)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
-- name: CreateOCRJob :one
|
||||
INSERT INTO ocr_jobs (resource_id, file_path, status)
|
||||
VALUES ($1, $2, 'pending')
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetOCRJob :one
|
||||
SELECT * FROM ocr_jobs
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: ListPendingOCRJobs :many
|
||||
SELECT * FROM ocr_jobs
|
||||
WHERE status = 'pending'
|
||||
ORDER BY created_at ASC;
|
||||
|
||||
-- name: UpdateOCRJobStatus :exec
|
||||
UPDATE ocr_jobs
|
||||
SET status = $1, error_message = $2, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $3;
|
||||
|
||||
-- name: DeleteOCRJob :exec
|
||||
DELETE FROM ocr_jobs
|
||||
WHERE id = $1;
|
||||
Reference in New Issue
Block a user