Skip to content

Conversation

@taroface
Copy link
Contributor

@taroface taroface commented Dec 8, 2025

DOC-14789

Update the ALTER TABLE example to drop & add constraint atomically. For the following reasons, this example did not work (and may have never worked):

  • The commands alter a PK with the wrong name (primary, not tablename_pkey as per convention).
  • The PK on the table used in the example (users) is referenced by several FKs in the MovR dataset, so the txn actually rolls back.
  • In 24.1, autocommit_before_ddl was introduced, which causes the txn to commit before issuing the DDL, which causes the statements to fail.
  • The original example issued multiple DDLs inside an explicit txn, which is an anti-pattern. Replaced the example to use a single ALTER TABLE with both DDL subcommands.
  • In 25.3, create_table_with_schema_locked was enabled by default, and the MovR tables were adjusted accordingly. This means the tables disallow schema changes unless the schema_locked storage param is disabled on the table.

The examples are updated (appropriately for each version) to use a different MovR table (promo_codes), use the correct PK name, disable autocommit_before_ddl, and disable/re-enable schema_locked to allow the example to work.

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for cockroachdb-interactivetutorials-docs canceled.

Name Link
🔨 Latest commit 2a9e85e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-interactivetutorials-docs/deploys/694308ecba2ea10009abb776

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for cockroachdb-api-docs canceled.

Name Link
🔨 Latest commit 2a9e85e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-api-docs/deploys/694308ec672d940008252770

@netlify
Copy link

netlify bot commented Dec 8, 2025

Netlify Preview

Name Link
🔨 Latest commit 2a9e85e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-docs/deploys/694308ec238d3e0008606f81
😎 Deploy Preview https://deploy-preview-21542--cockroachdb-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@taroface taroface requested a review from a team as a code owner December 8, 2025 21:12
Copy link
Contributor

@rmloveland rmloveland left a comment

Choose a reason for hiding this comment

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

LGTM modulo the multi DDL inside one transaction thing which we explicitly recommend against in https://www.cockroachlabs.com/docs/v25.4/online-schema-changes#schema-changes-within-transactions

@taroface taroface force-pushed the add-drop-constraint branch from 9fcb5fc to e368fde Compare December 15, 2025 20:04
@taroface taroface requested a review from rmloveland December 15, 2025 21:48
Copy link
Contributor

@rmloveland rmloveland left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@taroface taroface enabled auto-merge (squash) December 17, 2025 19:47
@taroface taroface merged commit bcc8975 into main Dec 17, 2025
6 checks passed
@taroface taroface deleted the add-drop-constraint branch December 17, 2025 20:01
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.

2 participants