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:
@@ -7,6 +7,8 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addClientCanSync = `-- name: AddClientCanSync :exec
|
||||
@@ -43,6 +45,124 @@ func (q *Queries) CreateClient(ctx context.Context, arg *CreateClientParams) err
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAllFoldersForClient = `-- name: DeleteAllFoldersForClient :exec
|
||||
DELETE FROM folders WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete all folders for a client. All documents must already be deleted to avoid FK violations.
|
||||
//
|
||||
// DELETE FROM folders WHERE clientId = $1
|
||||
func (q *Queries) DeleteAllFoldersForClient(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteAllFoldersForClient, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteBatchUploads = `-- name: DeleteBatchUploads :exec
|
||||
DELETE FROM batch_uploads WHERE client_id = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete all batch upload records for a client
|
||||
//
|
||||
// DELETE FROM batch_uploads WHERE client_id = $1
|
||||
func (q *Queries) DeleteBatchUploads(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteBatchUploads, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteClientCanSync = `-- name: DeleteClientCanSync :exec
|
||||
DELETE FROM clientCanSync WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete clientCanSync records for a client
|
||||
//
|
||||
// DELETE FROM clientCanSync WHERE clientId = $1
|
||||
func (q *Queries) DeleteClientCanSync(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteClientCanSync, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteCollectorActiveVersions = `-- name: DeleteCollectorActiveVersions :exec
|
||||
DELETE FROM collectorActiveVersions WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete collector active version records for a client
|
||||
//
|
||||
// DELETE FROM collectorActiveVersions WHERE clientId = $1
|
||||
func (q *Queries) DeleteCollectorActiveVersions(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteCollectorActiveVersions, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteCollectorMinCleanVersions = `-- name: DeleteCollectorMinCleanVersions :exec
|
||||
DELETE FROM collectorMinCleanVersions WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete collector minimum clean version records for a client
|
||||
//
|
||||
// DELETE FROM collectorMinCleanVersions WHERE clientId = $1
|
||||
func (q *Queries) DeleteCollectorMinCleanVersions(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteCollectorMinCleanVersions, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteCollectorVersions = `-- name: DeleteCollectorVersions :exec
|
||||
DELETE FROM collectorVersions WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete collector version records for a client
|
||||
//
|
||||
// DELETE FROM collectorVersions WHERE clientId = $1
|
||||
func (q *Queries) DeleteCollectorVersions(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteCollectorVersions, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteDocumentUploadsForClient = `-- name: DeleteDocumentUploadsForClient :exec
|
||||
DELETE FROM documentUploads WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Delete all documentUploads for a client
|
||||
//
|
||||
// DELETE FROM documentUploads WHERE clientId = $1
|
||||
func (q *Queries) DeleteDocumentUploadsForClient(ctx context.Context, clientID string) error {
|
||||
_, err := q.db.Exec(ctx, deleteDocumentUploadsForClient, clientID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllDocumentIDsForClient = `-- name: GetAllDocumentIDsForClient :many
|
||||
SELECT id FROM documents WHERE clientId = $1
|
||||
`
|
||||
|
||||
// Get all document IDs for a client, used to cascade document deletes during client delete
|
||||
//
|
||||
// SELECT id FROM documents WHERE clientId = $1
|
||||
func (q *Queries) GetAllDocumentIDsForClient(ctx context.Context, clientID string) ([]uuid.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, getAllDocumentIDsForClient, clientID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []uuid.UUID{}
|
||||
for rows.Next() {
|
||||
var id uuid.UUID
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, id)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getClient = `-- name: GetClient :one
|
||||
SELECT clientid, name, cansync FROM fullClients WHERE clientId = $1
|
||||
`
|
||||
@@ -57,6 +177,22 @@ func (q *Queries) GetClient(ctx context.Context, clientid string) (*Fullclient,
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const hardDeleteClient = `-- name: HardDeleteClient :execrows
|
||||
DELETE FROM clients WHERE clientId = $1
|
||||
`
|
||||
|
||||
// @sqlc-vet-disable
|
||||
// Hard delete the client row itself. Returns the number of rows deleted (0 or 1).
|
||||
//
|
||||
// DELETE FROM clients WHERE clientId = $1
|
||||
func (q *Queries) HardDeleteClient(ctx context.Context, clientID string) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, hardDeleteClient, clientID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const isClientSynced = `-- name: IsClientSynced :one
|
||||
WITH
|
||||
docs AS (
|
||||
|
||||
Reference in New Issue
Block a user