create content version
This commit is contained in:
@@ -90,6 +90,88 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createBlob = `-- name: CreateBlob :exec
|
||||
INSERT INTO blob (
|
||||
root,
|
||||
size,
|
||||
state,
|
||||
role,
|
||||
unit_size,
|
||||
tree_state,
|
||||
encryption,
|
||||
created_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7,
|
||||
?8
|
||||
)
|
||||
`
|
||||
|
||||
type CreateBlobParams struct {
|
||||
Root []byte
|
||||
Size int64
|
||||
State string
|
||||
Role string
|
||||
UnitSize int64
|
||||
TreeState string
|
||||
Encryption string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBlob(ctx context.Context, arg CreateBlobParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createBlob,
|
||||
arg.Root,
|
||||
arg.Size,
|
||||
arg.State,
|
||||
arg.Role,
|
||||
arg.UnitSize,
|
||||
arg.TreeState,
|
||||
arg.Encryption,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const createBlobLocation = `-- name: CreateBlobLocation :exec
|
||||
INSERT INTO blob_location (
|
||||
root,
|
||||
backend_id,
|
||||
locator,
|
||||
state,
|
||||
created_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5
|
||||
)
|
||||
`
|
||||
|
||||
type CreateBlobLocationParams struct {
|
||||
Root []byte
|
||||
BackendID ident.UUID
|
||||
Locator string
|
||||
State string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBlobLocation(ctx context.Context, arg CreateBlobLocationParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createBlobLocation,
|
||||
arg.Root,
|
||||
arg.BackendID,
|
||||
arg.Locator,
|
||||
arg.State,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const createDocument = `-- name: CreateDocument :one
|
||||
INSERT INTO document (
|
||||
id,
|
||||
@@ -202,6 +284,86 @@ func (q *Queries) CreateDocument(ctx context.Context, arg CreateDocumentParams)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createDocumentVersion = `-- name: CreateDocumentVersion :one
|
||||
INSERT INTO document_version (
|
||||
id,
|
||||
document_id,
|
||||
seq,
|
||||
content_root,
|
||||
size,
|
||||
mime,
|
||||
author_id,
|
||||
device_id,
|
||||
origin,
|
||||
message,
|
||||
pinned,
|
||||
created_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7,
|
||||
?8,
|
||||
?9,
|
||||
?10,
|
||||
?11,
|
||||
?12
|
||||
)
|
||||
RETURNING id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at
|
||||
`
|
||||
|
||||
type CreateDocumentVersionParams struct {
|
||||
ID ident.UUID
|
||||
DocumentID ident.UUID
|
||||
Seq int64
|
||||
ContentRoot []byte
|
||||
Size int64
|
||||
Mime sql.NullString
|
||||
AuthorID ident.UUID
|
||||
DeviceID *ident.UUID
|
||||
Origin string
|
||||
Message sql.NullString
|
||||
Pinned int64
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateDocumentVersion(ctx context.Context, arg CreateDocumentVersionParams) (DocumentVersion, error) {
|
||||
row := q.db.QueryRowContext(ctx, createDocumentVersion,
|
||||
arg.ID,
|
||||
arg.DocumentID,
|
||||
arg.Seq,
|
||||
arg.ContentRoot,
|
||||
arg.Size,
|
||||
arg.Mime,
|
||||
arg.AuthorID,
|
||||
arg.DeviceID,
|
||||
arg.Origin,
|
||||
arg.Message,
|
||||
arg.Pinned,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i DocumentVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DocumentID,
|
||||
&i.Seq,
|
||||
&i.ContentRoot,
|
||||
&i.Size,
|
||||
&i.Mime,
|
||||
&i.AuthorID,
|
||||
&i.DeviceID,
|
||||
&i.Origin,
|
||||
&i.Message,
|
||||
&i.Pinned,
|
||||
&i.ContentPurgedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createMembership = `-- name: CreateMembership :one
|
||||
|
||||
INSERT INTO membership (
|
||||
@@ -387,6 +549,100 @@ func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (S
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createStagingItem = `-- name: CreateStagingItem :exec
|
||||
|
||||
INSERT INTO staging_item (
|
||||
id,
|
||||
origin,
|
||||
job_ref,
|
||||
locator,
|
||||
size,
|
||||
state,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7,
|
||||
?8
|
||||
)
|
||||
`
|
||||
|
||||
type CreateStagingItemParams struct {
|
||||
ID ident.UUID
|
||||
Origin string
|
||||
JobRef sql.NullString
|
||||
Locator string
|
||||
Size sql.NullInt64
|
||||
State string
|
||||
CreatedAt int64
|
||||
UpdatedAt int64
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// staging_item
|
||||
// ============================================================================
|
||||
func (q *Queries) CreateStagingItem(ctx context.Context, arg CreateStagingItemParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createStagingItem,
|
||||
arg.ID,
|
||||
arg.Origin,
|
||||
arg.JobRef,
|
||||
arg.Locator,
|
||||
arg.Size,
|
||||
arg.State,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const createStorageBackend = `-- name: CreateStorageBackend :exec
|
||||
INSERT INTO storage_backend (
|
||||
id,
|
||||
kind,
|
||||
name,
|
||||
config,
|
||||
enabled,
|
||||
state,
|
||||
created_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7
|
||||
)
|
||||
`
|
||||
|
||||
type CreateStorageBackendParams struct {
|
||||
ID ident.UUID
|
||||
Kind string
|
||||
Name string
|
||||
Config string
|
||||
Enabled int64
|
||||
State string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
func (q *Queries) CreateStorageBackend(ctx context.Context, arg CreateStorageBackendParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createStorageBackend,
|
||||
arg.ID,
|
||||
arg.Kind,
|
||||
arg.Name,
|
||||
arg.Config,
|
||||
arg.Enabled,
|
||||
arg.State,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAccount = `-- name: DeleteAccount :exec
|
||||
DELETE FROM account
|
||||
WHERE principal_id = ?1
|
||||
@@ -487,6 +743,61 @@ func (q *Queries) GetAccountByLoginKey(ctx context.Context, loginKey string) (Ac
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBlob = `-- name: GetBlob :one
|
||||
|
||||
SELECT root, size, state, role, unit_size, have, tree_state, encryption, last_verified_at, verify_error, last_access_at, created_at
|
||||
FROM blob
|
||||
WHERE root = ?1
|
||||
`
|
||||
|
||||
// ============================================================================
|
||||
// blob
|
||||
// ============================================================================
|
||||
func (q *Queries) GetBlob(ctx context.Context, root []byte) (Blob, error) {
|
||||
row := q.db.QueryRowContext(ctx, getBlob, root)
|
||||
var i Blob
|
||||
err := row.Scan(
|
||||
&i.Root,
|
||||
&i.Size,
|
||||
&i.State,
|
||||
&i.Role,
|
||||
&i.UnitSize,
|
||||
&i.Have,
|
||||
&i.TreeState,
|
||||
&i.Encryption,
|
||||
&i.LastVerifiedAt,
|
||||
&i.VerifyError,
|
||||
&i.LastAccessAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBlobLocation = `-- name: GetBlobLocation :one
|
||||
SELECT root, backend_id, locator, state, created_at
|
||||
FROM blob_location
|
||||
WHERE root = ?1
|
||||
AND backend_id = ?2
|
||||
`
|
||||
|
||||
type GetBlobLocationParams struct {
|
||||
Root []byte
|
||||
BackendID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) GetBlobLocation(ctx context.Context, arg GetBlobLocationParams) (BlobLocation, error) {
|
||||
row := q.db.QueryRowContext(ctx, getBlobLocation, arg.Root, arg.BackendID)
|
||||
var i BlobLocation
|
||||
err := row.Scan(
|
||||
&i.Root,
|
||||
&i.BackendID,
|
||||
&i.Locator,
|
||||
&i.State,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getClusterPrincipal = `-- name: GetClusterPrincipal :one
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
@@ -549,6 +860,83 @@ func (q *Queries) GetDocument(ctx context.Context, id ident.UUID) (Document, err
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDocumentKind = `-- name: GetDocumentKind :one
|
||||
|
||||
SELECT kind, provider, has_content, hidden, metadata_schema
|
||||
FROM document_kind
|
||||
WHERE kind = ?1
|
||||
`
|
||||
|
||||
// ============================================================================
|
||||
// document_kind
|
||||
// ============================================================================
|
||||
func (q *Queries) GetDocumentKind(ctx context.Context, kind string) (DocumentKind, error) {
|
||||
row := q.db.QueryRowContext(ctx, getDocumentKind, kind)
|
||||
var i DocumentKind
|
||||
err := row.Scan(
|
||||
&i.Kind,
|
||||
&i.Provider,
|
||||
&i.HasContent,
|
||||
&i.Hidden,
|
||||
&i.MetadataSchema,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDocumentVersion = `-- name: GetDocumentVersion :one
|
||||
|
||||
SELECT id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at
|
||||
FROM document_version
|
||||
WHERE id = ?1
|
||||
`
|
||||
|
||||
// ============================================================================
|
||||
// document_version
|
||||
// ============================================================================
|
||||
func (q *Queries) GetDocumentVersion(ctx context.Context, id ident.UUID) (DocumentVersion, error) {
|
||||
row := q.db.QueryRowContext(ctx, getDocumentVersion, id)
|
||||
var i DocumentVersion
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DocumentID,
|
||||
&i.Seq,
|
||||
&i.ContentRoot,
|
||||
&i.Size,
|
||||
&i.Mime,
|
||||
&i.AuthorID,
|
||||
&i.DeviceID,
|
||||
&i.Origin,
|
||||
&i.Message,
|
||||
&i.Pinned,
|
||||
&i.ContentPurgedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getEffectiveDocumentPolicy = `-- name: GetEffectiveDocumentPolicy :one
|
||||
WITH RECURSIVE chain(id, policy_id, parent_id) AS (
|
||||
SELECT d.id, d.policy_id, d.parent_id
|
||||
FROM document d
|
||||
WHERE d.id = ?1
|
||||
UNION ALL
|
||||
SELECT d.id, COALESCE(d.policy_id, chain.policy_id), d.parent_id
|
||||
FROM document d
|
||||
JOIN chain ON d.id = chain.parent_id
|
||||
)
|
||||
SELECT policy_id
|
||||
FROM chain
|
||||
WHERE policy_id IS NOT NULL
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetEffectiveDocumentPolicy(ctx context.Context, id ident.UUID) ([]byte, error) {
|
||||
row := q.db.QueryRowContext(ctx, getEffectiveDocumentPolicy, id)
|
||||
var policy_id []byte
|
||||
err := row.Scan(&policy_id)
|
||||
return policy_id, err
|
||||
}
|
||||
|
||||
const getMembership = `-- name: GetMembership :one
|
||||
SELECT group_id, member_id, role, created_at
|
||||
FROM membership
|
||||
@@ -697,6 +1085,35 @@ func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStorageBackend = `-- name: GetStorageBackend :one
|
||||
|
||||
SELECT id, kind, name, config, secret_ref, enabled, capacity_bytes, state, last_ok_at, last_error, created_at
|
||||
FROM storage_backend
|
||||
WHERE id = ?1
|
||||
`
|
||||
|
||||
// ============================================================================
|
||||
// storage_backend
|
||||
// ============================================================================
|
||||
func (q *Queries) GetStorageBackend(ctx context.Context, id ident.UUID) (StorageBackend, error) {
|
||||
row := q.db.QueryRowContext(ctx, getStorageBackend, id)
|
||||
var i StorageBackend
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.Name,
|
||||
&i.Config,
|
||||
&i.SecretRef,
|
||||
&i.Enabled,
|
||||
&i.CapacityBytes,
|
||||
&i.State,
|
||||
&i.LastOkAt,
|
||||
&i.LastError,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStoragePolicy = `-- name: GetStoragePolicy :one
|
||||
|
||||
SELECT id, name, mode, min_remote_replicas, replicate_history, cache_ttl_s, cache_max_bytes, version_retention, created_at
|
||||
@@ -836,6 +1253,42 @@ func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error)
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listBlobLocations = `-- name: ListBlobLocations :many
|
||||
SELECT root, backend_id, locator, state, created_at
|
||||
FROM blob_location
|
||||
WHERE root = ?1
|
||||
ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ListBlobLocations(ctx context.Context, root []byte) ([]BlobLocation, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listBlobLocations, root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BlobLocation
|
||||
for rows.Next() {
|
||||
var i BlobLocation
|
||||
if err := rows.Scan(
|
||||
&i.Root,
|
||||
&i.BackendID,
|
||||
&i.Locator,
|
||||
&i.State,
|
||||
&i.CreatedAt,
|
||||
); 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 listDocumentChildren = `-- name: ListDocumentChildren :many
|
||||
SELECT id, kind, owner_id, created_by, parent_id, name, name_key, path, depth, position, head_version_id, metadata, policy_id, visibility, acl_inherit, rev, created_at, updated_at, deleted_at, deleted_by, trash_batch
|
||||
FROM document
|
||||
@@ -947,6 +1400,50 @@ func (q *Queries) ListDocumentDescendants(ctx context.Context, arg ListDocumentD
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDocumentVersions = `-- name: ListDocumentVersions :many
|
||||
SELECT id, document_id, seq, content_root, size, mime, author_id, device_id, origin, message, pinned, content_purged_at, created_at
|
||||
FROM document_version
|
||||
WHERE document_id = ?1
|
||||
ORDER BY seq DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListDocumentVersions(ctx context.Context, documentID ident.UUID) ([]DocumentVersion, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listDocumentVersions, documentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []DocumentVersion
|
||||
for rows.Next() {
|
||||
var i DocumentVersion
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.DocumentID,
|
||||
&i.Seq,
|
||||
&i.ContentRoot,
|
||||
&i.Size,
|
||||
&i.Mime,
|
||||
&i.AuthorID,
|
||||
&i.DeviceID,
|
||||
&i.Origin,
|
||||
&i.Message,
|
||||
&i.Pinned,
|
||||
&i.ContentPurgedAt,
|
||||
&i.CreatedAt,
|
||||
); 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 listGroupMembers = `-- name: ListGroupMembers :many
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
|
||||
FROM membership m
|
||||
@@ -1443,6 +1940,19 @@ func (q *Queries) MoveDocument(ctx context.Context, arg MoveDocumentParams) (Doc
|
||||
return i, err
|
||||
}
|
||||
|
||||
const nextDocumentVersionSeq = `-- name: NextDocumentVersionSeq :one
|
||||
SELECT COALESCE(MAX(seq), 0) + 1 AS seq
|
||||
FROM document_version
|
||||
WHERE document_id = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) NextDocumentVersionSeq(ctx context.Context, documentID ident.UUID) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, nextDocumentVersionSeq, documentID)
|
||||
var seq int64
|
||||
err := row.Scan(&seq)
|
||||
return seq, err
|
||||
}
|
||||
|
||||
const recordLogin = `-- name: RecordLogin :one
|
||||
UPDATE account
|
||||
SET last_login_at = ?1,
|
||||
@@ -1663,6 +2173,29 @@ func (q *Queries) RevokeSessionByTokenHash(ctx context.Context, arg RevokeSessio
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setDocumentHeadVersion = `-- name: SetDocumentHeadVersion :execrows
|
||||
UPDATE document
|
||||
SET head_version_id = ?1,
|
||||
rev = rev + 1,
|
||||
updated_at = ?2
|
||||
WHERE id = ?3
|
||||
AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type SetDocumentHeadVersionParams struct {
|
||||
HeadVersionID *ident.UUID
|
||||
UpdatedAt int64
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) SetDocumentHeadVersion(ctx context.Context, arg SetDocumentHeadVersionParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, setDocumentHeadVersion, arg.HeadVersionID, arg.UpdatedAt, arg.ID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const touchSession = `-- name: TouchSession :one
|
||||
UPDATE session
|
||||
SET last_seen_at = ?1,
|
||||
@@ -2043,6 +2576,24 @@ func (q *Queries) UpdatePrincipalSuccessor(ctx context.Context, arg UpdatePrinci
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateStagingItemState = `-- name: UpdateStagingItemState :exec
|
||||
UPDATE staging_item
|
||||
SET state = ?1,
|
||||
updated_at = ?2
|
||||
WHERE id = ?3
|
||||
`
|
||||
|
||||
type UpdateStagingItemStateParams struct {
|
||||
State string
|
||||
UpdatedAt int64
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStagingItemState(ctx context.Context, arg UpdateStagingItemStateParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateStagingItemState, arg.State, arg.UpdatedAt, arg.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertACLEntry = `-- name: UpsertACLEntry :one
|
||||
|
||||
INSERT INTO acl_entry (
|
||||
|
||||
Reference in New Issue
Block a user