Skip to content

feat: add noTransaction parameter to tables.create() and columns.crea…#1049

Closed
7ttp wants to merge 2 commits intosupabase:masterfrom
7ttp:feat/no-transaction-parameter
Closed

feat: add noTransaction parameter to tables.create() and columns.crea…#1049
7ttp wants to merge 2 commits intosupabase:masterfrom
7ttp:feat/no-transaction-parameter

Conversation

@7ttp
Copy link
Copy Markdown

@7ttp 7ttp commented Mar 3, 2026

Summary

Adds optional noTransaction parameter to tables.create() and columns.create() that skips BEGIN...COMMIT wrappers when set to true, enabling atomic multi-operation transactions.

Problem

Each create() call wraps SQL in its own transaction.

Solution

Added noTransaction parameter (defaults to false for BC) that conditionally wraps SQL.

Related

@7ttp 7ttp requested review from a team, avallete and soedirgo as code owners March 3, 2026 15:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 0401ceae-b11a-4299-99e4-e0eb1abe95ac

📥 Commits

Reviewing files that changed from the base of the PR and between 7fe7a09 and ef41be8.

📒 Files selected for processing (1)
  • src/lib/PostgresMetaColumns.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added an optional non-transactional mode for creating database tables and columns, allowing create and comment operations to run without being wrapped in a transaction.

Walkthrough

This PR adds a noTransaction boolean parameter to the PostgresMetaColumns.create() and PostgresMetaTables.create() methods, with a default value of false. The parameter controls whether the generated SQL statements are wrapped in a transaction. When noTransaction is true, the SQL executes without BEGIN/COMMIT. When false (default), operations remain wrapped in a transaction as before. The corresponding type definitions in PostgresColumnCreate and PostgresTableCreate are updated to include this optional field.

Sequence Diagram(s)

(omitted)

Assessment against linked issues

Objective Addressed Explanation
Make table creation atomic so that if a column creation fails, the entire table creation is rolled back [#42089] The PR exposes a noTransaction flag but does not change default transactional behavior; it's unclear whether callers will use this to ensure table+column creation occur in a single transaction.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/lib/PostgresMetaColumns.ts Outdated
@7ttp
Copy link
Copy Markdown
Author

7ttp commented Mar 13, 2026

@avallete @mandarini

Copy link
Copy Markdown
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m leaning against approving this.

I’d rather keep postgres-meta endpoints atomic by default and avoid adding app-specific transaction control to these helpers. For cases like this, Studio should build and own the full SQL/transaction it needs and use the lower-level query path instead of extending the tables.create() / columns.create() API surface with noTransaction.

djhi added a commit to supabase/supabase that referenced this pull request Mar 19, 2026
Fixes #42089
Supersedes #43352 and
supabase/postgres-meta#1049

## Problem

When creating a table in the Dashboard, if a column-specific error
occurs (e.g., invalid enum value or broken foreign key), the Dashboard
displays an error toast, but the side panel remains open. In the
background, the table is actually created (partially), leading to a
_42P07: relation already exists_ error if the user tries to click _Save_
again.

## Solution

We actually had nested transactions which is not supported by Postgres.

- [x] Allow generating SQL without transactions from `@supabase/pg-meta`
- [x] Fix the table creation
- [x] Fix some accessibility issues
- [x] Add tests

## How to test

1. Click _New table_ in the Table editor
2. Add a column with an _int8_ type and set its default value to
`bazinga`
3. Click _Save_

You should see an error.
4. Fix the default value by setting it to `10`
5. Click _Save_

Results:
- You should see a success message about the table creation
- The table should have the column with the correct default value
@djhi
Copy link
Copy Markdown

djhi commented Mar 19, 2026

Closed in favor of #43909. Thanks!

@djhi djhi closed this Mar 19, 2026
@7ttp 7ttp deleted the feat/no-transaction-parameter branch March 19, 2026 08:40
stylessh pushed a commit to supabase/supabase that referenced this pull request Mar 23, 2026
Fixes #42089
Supersedes #43352 and
supabase/postgres-meta#1049

## Problem

When creating a table in the Dashboard, if a column-specific error
occurs (e.g., invalid enum value or broken foreign key), the Dashboard
displays an error toast, but the side panel remains open. In the
background, the table is actually created (partially), leading to a
_42P07: relation already exists_ error if the user tries to click _Save_
again.

## Solution

We actually had nested transactions which is not supported by Postgres.

- [x] Allow generating SQL without transactions from `@supabase/pg-meta`
- [x] Fix the table creation
- [x] Fix some accessibility issues
- [x] Add tests

## How to test

1. Click _New table_ in the Table editor
2. Add a column with an _int8_ type and set its default value to
`bazinga`
3. Click _Save_

You should see an error.
4. Fix the default value by setting it to `10`
5. Click _Save_

Results:
- You should see a success message about the table creation
- The table should have the column with the correct default value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table Editor allows partial creation and remains open on SQL error

3 participants