@@ -546,3 +546,27 @@ WHERE
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Documents) BulkSoftDelete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE documents SET deleted_at = @deleted_at WHERE %s AND id = ANY(@document_ids)
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
ids := make([]gid.GID, len(*p))
|
||||
for i, doc := range *p {
|
||||
ids[i] = doc.ID
|
||||
}
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"document_ids": ids,
|
||||
"deleted_at": time.Now()}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -55,5 +55,5 @@ const (
|
||||
SnapshotEntityType
|
||||
ContinualImprovementEntityType
|
||||
ProcessingActivityEntityType
|
||||
FrameworkExportEntityType
|
||||
ExportJobEntityType
|
||||
)
|
||||
|
||||
246
pkg/coredata/export_job.go
Normal file
246
pkg/coredata/export_job.go
Normal file
@@ -0,0 +1,246 @@
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
ExportJob struct {
|
||||
ID gid.GID `db:"id"`
|
||||
Type ExportJobType `db:"type"`
|
||||
Arguments json.RawMessage `db:"arguments"`
|
||||
Error *string `db:"error"`
|
||||
Status ExportJobStatus `db:"status"`
|
||||
FileID *gid.GID `db:"file_id"`
|
||||
RecipientEmail string `db:"recipient_email"`
|
||||
RecipientName string `db:"recipient_name"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
StartedAt *time.Time `db:"started_at"`
|
||||
CompletedAt *time.Time `db:"completed_at"`
|
||||
}
|
||||
|
||||
ExportJobs []*ExportJob
|
||||
|
||||
DocumentExportArguments struct {
|
||||
DocumentIDs []gid.GID `json:"document_ids"`
|
||||
}
|
||||
|
||||
FrameworkExportArguments struct {
|
||||
FrameworkID gid.GID `json:"framework_id"`
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoExportJobAvailable = errors.New("no export job available")
|
||||
)
|
||||
|
||||
func (ej *ExportJob) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO export_jobs (
|
||||
id,
|
||||
tenant_id,
|
||||
type,
|
||||
arguments,
|
||||
status,
|
||||
recipient_email,
|
||||
recipient_name,
|
||||
created_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@type,
|
||||
@arguments,
|
||||
@status,
|
||||
@recipient_email,
|
||||
@recipient_name,
|
||||
@created_at
|
||||
)`
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": ej.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"type": ej.Type,
|
||||
"arguments": ej.Arguments,
|
||||
"status": ej.Status,
|
||||
"recipient_email": ej.RecipientEmail,
|
||||
"recipient_name": ej.RecipientName,
|
||||
"created_at": ej.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ej *ExportJob) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE
|
||||
export_jobs
|
||||
SET
|
||||
status = @status,
|
||||
error = @error,
|
||||
file_id = @file_id,
|
||||
started_at = @started_at,
|
||||
completed_at = @completed_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
args := pgx.StrictNamedArgs{
|
||||
"status": ej.Status,
|
||||
"error": ej.Error,
|
||||
"file_id": ej.FileID,
|
||||
"started_at": ej.StartedAt,
|
||||
"completed_at": ej.CompletedAt,
|
||||
"id": ej.ID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ej *ExportJob) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
id gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
type,
|
||||
arguments,
|
||||
error,
|
||||
status,
|
||||
file_id,
|
||||
recipient_email,
|
||||
recipient_name,
|
||||
created_at,
|
||||
started_at,
|
||||
completed_at
|
||||
FROM
|
||||
export_jobs
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
args := pgx.StrictNamedArgs{"id": id}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ej2, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ExportJob])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect export job: %w", err)
|
||||
}
|
||||
|
||||
*ej = ej2
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ej *ExportJob) LoadNextPendingForUpdateSkipLocked(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
type,
|
||||
arguments,
|
||||
error,
|
||||
status,
|
||||
file_id,
|
||||
recipient_email,
|
||||
recipient_name,
|
||||
created_at,
|
||||
started_at,
|
||||
completed_at
|
||||
FROM
|
||||
export_jobs
|
||||
WHERE
|
||||
status = @status
|
||||
ORDER BY
|
||||
created_at ASC
|
||||
LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
`
|
||||
args := pgx.StrictNamedArgs{
|
||||
"status": ExportJobStatusPending,
|
||||
}
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ej2, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ExportJob])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrNoExportJobAvailable
|
||||
}
|
||||
return fmt.Errorf("cannot collect export job: %w", err)
|
||||
}
|
||||
|
||||
*ej = ej2
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ej *ExportJob) GetDocumentExportArguments() (*DocumentExportArguments, error) {
|
||||
if ej.Type != ExportJobTypeDocument {
|
||||
return nil, fmt.Errorf("export job is not a document export")
|
||||
}
|
||||
|
||||
var args DocumentExportArguments
|
||||
if err := json.Unmarshal(ej.Arguments, &args); err != nil {
|
||||
return nil, fmt.Errorf("cannot unmarshal document export arguments: %w", err)
|
||||
}
|
||||
|
||||
return &args, nil
|
||||
}
|
||||
|
||||
func (ej *ExportJob) GetFrameworkExportArguments() (*FrameworkExportArguments, error) {
|
||||
if ej.Type != ExportJobTypeFramework {
|
||||
return nil, fmt.Errorf("export job is not a framework export")
|
||||
}
|
||||
|
||||
var args FrameworkExportArguments
|
||||
if err := json.Unmarshal(ej.Arguments, &args); err != nil {
|
||||
return nil, fmt.Errorf("cannot unmarshal framework export arguments: %w", err)
|
||||
}
|
||||
|
||||
return &args, nil
|
||||
}
|
||||
|
||||
func (ej *ExportJob) GetDocumentIDs() ([]gid.GID, error) {
|
||||
args, err := ej.GetDocumentExportArguments()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return args.DocumentIDs, nil
|
||||
}
|
||||
|
||||
func (ej *ExportJob) GetFrameworkID() (gid.GID, error) {
|
||||
args, err := ej.GetFrameworkExportArguments()
|
||||
if err != nil {
|
||||
return gid.GID{}, err
|
||||
}
|
||||
return args.FrameworkID, nil
|
||||
}
|
||||
51
pkg/coredata/export_job_status.go
Normal file
51
pkg/coredata/export_job_status.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
ExportJobStatus string
|
||||
)
|
||||
|
||||
const (
|
||||
ExportJobStatusPending ExportJobStatus = "PENDING"
|
||||
ExportJobStatusProcessing ExportJobStatus = "PROCESSING"
|
||||
ExportJobStatusCompleted ExportJobStatus = "COMPLETED"
|
||||
ExportJobStatusFailed ExportJobStatus = "FAILED"
|
||||
)
|
||||
|
||||
func (ejs ExportJobStatus) String() string {
|
||||
return string(ejs)
|
||||
}
|
||||
|
||||
func (ejs *ExportJobStatus) Scan(value any) error {
|
||||
var s string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
case []byte:
|
||||
s = string(v)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for ExportJobStatus: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case ExportJobStatusPending.String():
|
||||
*ejs = ExportJobStatusPending
|
||||
case ExportJobStatusProcessing.String():
|
||||
*ejs = ExportJobStatusProcessing
|
||||
case ExportJobStatusCompleted.String():
|
||||
*ejs = ExportJobStatusCompleted
|
||||
case ExportJobStatusFailed.String():
|
||||
*ejs = ExportJobStatusFailed
|
||||
default:
|
||||
return fmt.Errorf("invalid ExportJobStatus value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ejs ExportJobStatus) Value() (driver.Value, error) {
|
||||
return ejs.String(), nil
|
||||
}
|
||||
45
pkg/coredata/export_job_type.go
Normal file
45
pkg/coredata/export_job_type.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
ExportJobType string
|
||||
)
|
||||
|
||||
const (
|
||||
ExportJobTypeFramework ExportJobType = "FRAMEWORK"
|
||||
ExportJobTypeDocument ExportJobType = "DOCUMENT"
|
||||
)
|
||||
|
||||
func (ejt ExportJobType) String() string {
|
||||
return string(ejt)
|
||||
}
|
||||
|
||||
func (ejt *ExportJobType) Scan(value any) error {
|
||||
var s string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
case []byte:
|
||||
s = string(v)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for ExportJobType: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case ExportJobTypeFramework.String():
|
||||
*ejt = ExportJobTypeFramework
|
||||
case ExportJobTypeDocument.String():
|
||||
*ejt = ExportJobTypeDocument
|
||||
default:
|
||||
return fmt.Errorf("invalid ExportJobType value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ejt ExportJobType) Value() (driver.Value, error) {
|
||||
return ejt.String(), nil
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
FrameworkExport struct {
|
||||
ID gid.GID `db:"id"`
|
||||
FrameworkID gid.GID `db:"framework_id"`
|
||||
RecipientEmail string `db:"recipient_email"`
|
||||
RecipientName string `db:"recipient_name"`
|
||||
Status FrameworkExportStatus `db:"status"`
|
||||
FileID *gid.GID `db:"file_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
StartedAt *time.Time `db:"started_at"`
|
||||
CompletedAt *time.Time `db:"completed_at"`
|
||||
}
|
||||
|
||||
FrameworkExports []*FrameworkExport
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoFrameworkExportAvailable = errors.New("no framework export available")
|
||||
)
|
||||
|
||||
func (fe FrameworkExport) CursorKey(orderBy FrameworkExportOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case FrameworkExportOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(fe.ID, fe.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (fe *FrameworkExport) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO framework_exports (
|
||||
id,
|
||||
tenant_id,
|
||||
framework_id,
|
||||
recipient_email,
|
||||
recipient_name,
|
||||
status,
|
||||
created_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@framework_id,
|
||||
@recipient_email,
|
||||
@recipient_name,
|
||||
@status,
|
||||
@created_at
|
||||
)`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": fe.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"framework_id": fe.FrameworkID,
|
||||
"recipient_email": fe.RecipientEmail,
|
||||
"recipient_name": fe.RecipientName,
|
||||
"status": fe.Status,
|
||||
"created_at": fe.CreatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (fe *FrameworkExport) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE
|
||||
framework_exports
|
||||
SET
|
||||
status = @status,
|
||||
file_id = @file_id,
|
||||
started_at = @started_at,
|
||||
completed_at = @completed_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"status": fe.Status,
|
||||
"file_id": fe.FileID,
|
||||
"started_at": fe.StartedAt,
|
||||
"completed_at": fe.CompletedAt,
|
||||
"id": fe.ID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (fe *FrameworkExport) LoadNextPendingForUpdateSkipLocked(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
framework_id,
|
||||
recipient_email,
|
||||
recipient_name,
|
||||
status,
|
||||
file_id,
|
||||
created_at,
|
||||
started_at,
|
||||
completed_at
|
||||
FROM
|
||||
framework_exports
|
||||
WHERE
|
||||
status = @status
|
||||
ORDER BY
|
||||
created_at ASC
|
||||
LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{"status": FrameworkExportStatusPending}
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fe2, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[FrameworkExport])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrNoFrameworkExportAvailable
|
||||
}
|
||||
return fmt.Errorf("cannot collect framework export: %w", err)
|
||||
}
|
||||
|
||||
*fe = fe2
|
||||
return nil
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
FrameworkExportOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
FrameworkExportOrderFieldCreatedAt FrameworkExportOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p FrameworkExportOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p FrameworkExportOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p FrameworkExportOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *FrameworkExportOrderField) UnmarshalText(text []byte) error {
|
||||
*p = FrameworkExportOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
FrameworkExportStatus string
|
||||
)
|
||||
|
||||
const (
|
||||
FrameworkExportStatusPending FrameworkExportStatus = "pending"
|
||||
FrameworkExportStatusProcessing FrameworkExportStatus = "processing"
|
||||
FrameworkExportStatusCompleted FrameworkExportStatus = "completed"
|
||||
FrameworkExportStatusFailed FrameworkExportStatus = "failed"
|
||||
)
|
||||
|
||||
func (pvs FrameworkExportStatus) MarshalText() ([]byte, error) {
|
||||
return []byte(pvs.String()), nil
|
||||
}
|
||||
|
||||
func (pvs *FrameworkExportStatus) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
|
||||
switch val {
|
||||
case FrameworkExportStatusPending.String():
|
||||
*pvs = FrameworkExportStatusPending
|
||||
case FrameworkExportStatusProcessing.String():
|
||||
*pvs = FrameworkExportStatusProcessing
|
||||
case FrameworkExportStatusCompleted.String():
|
||||
*pvs = FrameworkExportStatusCompleted
|
||||
case FrameworkExportStatusFailed.String():
|
||||
*pvs = FrameworkExportStatusFailed
|
||||
default:
|
||||
return fmt.Errorf("invalid FrameworkExportStatus value: %q", val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pvs FrameworkExportStatus) String() string {
|
||||
var val string
|
||||
|
||||
switch pvs {
|
||||
case FrameworkExportStatusPending:
|
||||
val = "pending"
|
||||
case FrameworkExportStatusProcessing:
|
||||
val = "processing"
|
||||
case FrameworkExportStatusCompleted:
|
||||
val = "completed"
|
||||
case FrameworkExportStatusFailed:
|
||||
val = "failed"
|
||||
default:
|
||||
panic(fmt.Errorf("invalid FrameworkExportStatus value: %q", string(pvs)))
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (pvs *FrameworkExportStatus) Scan(value any) error {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for FrameworkExportStatus, expected string got %T", value)
|
||||
}
|
||||
|
||||
return pvs.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
func (pvs FrameworkExportStatus) Value() (driver.Value, error) {
|
||||
return pvs.String(), nil
|
||||
}
|
||||
34
pkg/coredata/migrations/20250916T121639Z.sql
Normal file
34
pkg/coredata/migrations/20250916T121639Z.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
CREATE TYPE export_jobs_status AS ENUM (
|
||||
'PENDING',
|
||||
'PROCESSING',
|
||||
'COMPLETED',
|
||||
'FAILED'
|
||||
);
|
||||
|
||||
CREATE TYPE export_jobs_type AS ENUM (
|
||||
'FRAMEWORK',
|
||||
'DOCUMENT'
|
||||
);
|
||||
|
||||
CREATE TABLE export_jobs (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id TEXT NOT NULL,
|
||||
type export_jobs_type NOT NULL,
|
||||
arguments JSONB NOT NULL,
|
||||
error TEXT,
|
||||
status export_jobs_status NOT NULL,
|
||||
file_id TEXT,
|
||||
recipient_email TEXT NOT NULL,
|
||||
recipient_name TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
started_at TIMESTAMP WITH TIME ZONE,
|
||||
completed_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
|
||||
ALTER TABLE export_jobs ADD CONSTRAINT export_jobs_file_id_fkey
|
||||
FOREIGN KEY (file_id)
|
||||
REFERENCES files(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE SET NULL;
|
||||
|
||||
DROP TABLE framework_exports;
|
||||
Reference in New Issue
Block a user