Files
supabase/apps/studio/data/database-queues/database-queues-create-mutation.test.ts
c777ca1c74 fix(studio): quote pgmq.create_partitioned interval args as text to f… (#52480)
## Problem

Creating a **partitioned queue** from the dashboard (Integrations →
Queues → Create queue)
  fails with:

  ```
Failed to create database queue: function
pgmq.create_partitioned(unknown, integer, integer) does not exist
  ```

The form submits `partitionInterval` / `retentionInterval` as numbers,
and `literal()`
in pg-format renders numbers unquoted, so the generated SQL passes bare
integers while
  `pgmq.create_partitioned` declares these parameters as `text`.

  Fixes #52479

  ## Solution

Convert the intervals with `String()` before passing them to `literal()`
so quoted text
  literals are generated, matching the function signature:

  ```sql
  select from pgmq.create_partitioned('my_queue', '10000', '100000');
  ```

When both intervals are unset, the arguments are omitted entirely so the
function
  defaults (`'10000'` / `'100000'`) apply instead of explicit `NULL`s.

  Basic and unlogged queue creation are untouched.

  ## Review instructions

1. Enable the Queues integration on a project running pgmq whose
`create_partitioned`
     takes text args (e.g. self-hosted / pgmq 1.5.x)
  2. Go to Integrations → Queues → Create queue
  3. Select "Partitioned queue" (default) and click Create queue
  4. Verify the queue appears in the list, and
     `select * from pgmq.list_queues()` reports `is_partitioned = true`

  ## Checklist

  Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style guide](https://github.com/supabase/supabase/tree/master
  /apps/docs/style-guide)

---------

Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 14:39:03 +01:00

66 lines
1.9 KiB
TypeScript

import { beforeEach, expect, test, vi } from 'vitest'
import { createDatabaseQueue } from './database-queues-create-mutation'
const mockExecuteSql = vi.fn()
vi.mock('@/data/sql/execute-sql-mutation', () => ({
executeSql: (...args: unknown[]) => mockExecuteSql(...args),
}))
beforeEach(() => {
mockExecuteSql.mockReset()
mockExecuteSql.mockResolvedValue({ result: [] })
})
const capturedSql = () => String(mockExecuteSql.mock.calls[0][0].sql)
test('partitioned queues pass the intervals as text literals', async () => {
await createDatabaseQueue({
projectRef: 'ref',
name: 'q',
type: 'partitioned',
enableRls: false,
configuration: { partitionInterval: 10000, retentionInterval: 100000 },
})
expect(capturedSql()).toContain(
"pgmq.create_partitioned('q', partition_interval => '10000', retention_interval => '100000')"
)
})
test('partitioned queues keep a single supplied interval', async () => {
await createDatabaseQueue({
projectRef: 'ref',
name: 'q',
type: 'partitioned',
enableRls: false,
configuration: { retentionInterval: 100000 },
})
expect(capturedSql()).toContain("pgmq.create_partitioned('q', retention_interval => '100000')")
})
test('partitioned queues without intervals use the function defaults', async () => {
await createDatabaseQueue({
projectRef: 'ref',
name: 'q',
type: 'partitioned',
enableRls: false,
})
expect(capturedSql()).toContain("pgmq.create_partitioned('q')")
})
test('basic queues use pgmq.create', async () => {
await createDatabaseQueue({ projectRef: 'ref', name: 'q', type: 'basic', enableRls: false })
expect(capturedSql()).toContain("pgmq.create('q')")
})
test('unlogged queues use pgmq.create_unlogged', async () => {
await createDatabaseQueue({ projectRef: 'ref', name: 'q', type: 'unlogged', enableRls: false })
expect(capturedSql()).toContain("pgmq.create_unlogged('q')")
})