Skip to content

bindings-macro: add custom index name to prevent index name collisions#4725

Open
rudcode wants to merge 1 commit intoclockworklabs:masterfrom
rudcode:master
Open

bindings-macro: add custom index name to prevent index name collisions#4725
rudcode wants to merge 1 commit intoclockworklabs:masterfrom
rudcode:master

Conversation

@rudcode
Copy link
Copy Markdown

@rudcode rudcode commented Mar 29, 2026

Description of Changes

SpacetimeDB generates colliding index names like product_category_id_idx_btree (category_id in product and id in product_category making same product_category_id prefix) , causing spacetime publish to fail with name used for multiple entities.

This PR allow users to specify custom index names:

// Before (error): index name collision
#[index(btree)]
pub category_id: u64,
// After (fix): specify unique name
#[index(btree, name = "product_category_id_idx_btree2")]
pub category_id: u64,

API and ABI breaking changes

None

Expected complexity level and risk

Complexity: 1
A simple change to only bindings-macro/src/table.rs. No breaking changes.

Testing

Manual testing with the reproducer from Issue #4719 - spacetime publish now succeeds when unique index names are provided. And when custom index name is changed, it successfully migrated.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

@rudcode rudcode force-pushed the master branch 2 times, most recently from 1df6c4d to 54d66af Compare March 30, 2026 02:26
@rudcode
Copy link
Copy Markdown
Author

rudcode commented Mar 30, 2026

I am just thinking, this maybe makes it hard to distinguish between old 1.x and 2.x syntax. Because old 1.x use name instead of accessor. This will remove all of the error when user wants to migrate from 1.x to 2.x. Do we need to rename the name to more explicit names like index_name?

@rudcode
Copy link
Copy Markdown
Author

rudcode commented Mar 30, 2026

Force pushed to add error message if name is Ident (we assume it's old 1.x code that need migration). name should be LitStr

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