Skip to content

Conversation

@Kiran01bm
Copy link
Collaborator

@Kiran01bm Kiran01bm commented Oct 15, 2025

What and Why ?

Allow legitimate same-table sequential operations esp when some of those hit TiDB parser limitations. To address - #487.

Before

ζ ./spirit --host="127.0.0.1:8033" --username="tsandbox" --password="msandbox" \                                                                                                                                                         
  --database="test_spirit" \
  --statement="ALTER TABLE json_table ADD COLUMN price DECIMAL(10,2) GENERATED ALWAYS AS (JSON_EXTRACT(metadata, '$.price')), ADD INDEX idx_price_category ((JSON_EXTRACT(metadata, '$.category'), JSON_EXTRACT(metadata, '$.price')))"
spirit: error: could not parse SQL statement: ALTER TABLE json_table ADD COLUMN price DECIMAL(10,2) GENERATED ALWAYS AS (JSON_EXTRACT(metadata, '$.price')), ADD INDEX idx_price_category ((JSON_EXTRACT(metadata, '$.category'), JSON_EXTRACT(metadata, '$.price')))

After

./spirit --host="127.0.0.1:8033" --username="tsandbox" --password="msandbox" \
  --database="test_spirit" \
  --statement="ALTER TABLE user_accounts ADD COLUMN status ENUM('active','inactive') DEFAULT 'active'; ALTER TABLE user_accounts ADD INDEX idx_status (status)"
INFO[0000] Starting spirit migration: concurrency=4 target-chunk-size=500ms
INFO[0000] attempting to acquire metadata lock
INFO[0000] acquired metadata lock: test_spirit.user_accounts-c294803c
INFO[0000] apply complete: instant-ddl=true inplace-ddl=false
INFO[0000] releasing metadata lock: test_spirit.user_accounts-c294803c

@Kiran01bm Kiran01bm requested a review from morgo October 15, 2025 02:21
@Kiran01bm Kiran01bm force-pushed the fix/exp-multi-table-validation branch from 1e676fe to 113d7eb Compare October 15, 2025 02:58
@morgo
Copy link
Collaborator

morgo commented Nov 2, 2025

I think there are some cases we need to think through where it might not be safe to coalesce multiple changes to the same table. Consider this case:

  • Change 1 adds a new column (colA) with a default value.
  • Change 2 changes the default value of colA.

The expected result is that existing rows get the default value of change 1, but through this they would all have only the new default.

Outside of defaults, I think it's mostly straight forward to collapse changes largely because spirit does not handle changes which can cause data loss/truncation.

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