feat(workspace): sqlc queries for workspace/worktree/credential

This commit is contained in:
2026-05-02 07:07:33 +08:00
parent e5800ef5dc
commit 08845f92d7
9 changed files with 838 additions and 0 deletions
@@ -0,0 +1,13 @@
-- name: UpsertCredential :one
INSERT INTO git_credentials (id, workspace_id, kind, username, encrypted_secret, fingerprint)
VALUES ($1,$2,$3,$4,$5,$6)
ON CONFLICT (workspace_id) DO UPDATE
SET kind = EXCLUDED.kind,
username = EXCLUDED.username,
encrypted_secret = EXCLUDED.encrypted_secret,
fingerprint = EXCLUDED.fingerprint,
updated_at = now()
RETURNING *;
-- name: GetCredentialByWorkspace :one
SELECT * FROM git_credentials WHERE workspace_id = $1;
+43
View File
@@ -0,0 +1,43 @@
-- name: CreateWorkspace :one
INSERT INTO workspaces (
id, project_id, slug, name, description,
git_remote_url, default_branch, main_path, sync_status
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
RETURNING *;
-- name: GetWorkspaceByID :one
SELECT * FROM workspaces WHERE id = $1;
-- name: GetWorkspaceBySlug :one
SELECT w.* FROM workspaces w
JOIN projects p ON p.id = w.project_id
WHERE p.slug = $1 AND w.slug = $2;
-- name: ListWorkspacesByProject :many
SELECT * FROM workspaces WHERE project_id = $1
ORDER BY created_at DESC;
-- name: UpdateWorkspaceCore :one
UPDATE workspaces
SET name = $2, description = $3, default_branch = $4, updated_at = now()
WHERE id = $1
RETURNING *;
-- name: UpdateWorkspaceSyncStatus :one
UPDATE workspaces
SET sync_status = $2,
last_synced_at = $3,
last_sync_error = $4,
updated_at = now()
WHERE id = $1
RETURNING *;
-- name: DeleteWorkspace :exec
DELETE FROM workspaces WHERE id = $1;
-- name: ResetStuckSyncStatuses :exec
UPDATE workspaces
SET sync_status = 'error',
last_sync_error = 'process_restarted_during_' || sync_status,
updated_at = now()
WHERE sync_status IN ('cloning', 'syncing');
+39
View File
@@ -0,0 +1,39 @@
-- name: CreateWorktree :one
INSERT INTO workspace_worktrees (
id, workspace_id, branch, path, status, active_holder, acquired_at
) VALUES ($1,$2,$3,$4,$5,$6,$7)
RETURNING *;
-- name: GetWorktreeByID :one
SELECT * FROM workspace_worktrees WHERE id = $1;
-- name: GetWorktreeByBranchForUpdate :one
SELECT * FROM workspace_worktrees
WHERE workspace_id = $1 AND branch = $2
FOR UPDATE;
-- name: ListWorktreesByWorkspace :many
SELECT * FROM workspace_worktrees
WHERE workspace_id = $1
ORDER BY created_at DESC;
-- name: SetWorktreeActive :one
UPDATE workspace_worktrees
SET status = 'active', active_holder = $2, acquired_at = now(), last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: SetWorktreeIdle :one
UPDATE workspace_worktrees
SET status = 'idle', active_holder = NULL, acquired_at = NULL, last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: SetWorktreePruning :one
UPDATE workspace_worktrees
SET status = 'pruning', last_used_at = now()
WHERE id = $1
RETURNING *;
-- name: DeleteWorktree :exec
DELETE FROM workspace_worktrees WHERE id = $1;