mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-25 06:36:37 +00:00
Major additions: - Complete Next.js studio application with 1600+ components - Docker support (Dockerfile.combined, docker-compose.yml) - GCP deployment documentation and benchmarks - SQL benchmark scripts for performance testing - Sentry integration for monitoring - Comprehensive test suite and mocks Studio features: - Dashboard and admin interfaces - Data visualization components - Authentication and user management - API integration with RuVector backend - Static data and public assets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { handleError, put } from 'data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { databaseKeys } from './keys'
|
|
|
|
export type MigrationUpsertVariables = {
|
|
projectRef: string
|
|
query: string
|
|
name?: string
|
|
idempotencyKey?: string
|
|
}
|
|
|
|
export async function upsertMigration({
|
|
projectRef,
|
|
query,
|
|
name,
|
|
idempotencyKey,
|
|
}: MigrationUpsertVariables) {
|
|
const headers: Record<string, string> = {}
|
|
if (idempotencyKey) {
|
|
headers['Idempotency-Key'] = idempotencyKey
|
|
}
|
|
|
|
const body: { query: string; name?: string } = { query }
|
|
if (name) {
|
|
body.name = name
|
|
}
|
|
|
|
const { data, error } = await put('/v1/projects/{ref}/database/migrations', {
|
|
params: { path: { ref: projectRef } },
|
|
body,
|
|
headers,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type MigrationUpsertData = Awaited<ReturnType<typeof upsertMigration>>
|
|
|
|
export const useMigrationUpsertMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<MigrationUpsertData, ResponseError, MigrationUpsertVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<MigrationUpsertData, ResponseError, MigrationUpsertVariables>({
|
|
mutationFn: (vars) => upsertMigration(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries({ queryKey: databaseKeys.migrations(projectRef) })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to upsert migration: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|