sqlite-database-integration icon indicating copy to clipboard operation
sqlite-database-integration copied to clipboard

Implement altering column with `SET DEFAULT` and `DROP DEFAULT`

Open JanJakes opened this issue 1 year ago • 1 comments

This PR implements the support for the following MySQL statements:

ALTER TABLE _tmp_table CHANGE name SET DEFAULT 'abc';
ALTER TABLE _tmp_table CHANGE name DROP DEFAULT;

It required a small refactor so that the CHANGE COLUMN logic can be extracted to a reusable method.

JanJakes avatar Aug 09 '24 08:08 JanJakes

@brandonpayton I took another stab at this. It required extracting all the column-changing logic to a private method, and allowing edits to the columns via a callback, so that the old column definition is available to statements like SET/DROP DEFAULT. See the first two commits for that part. The third commit implements the new functionality. I tried to make as few refactors as possible, although some things could be done in a better way, I suppose, but then there would be even more refactor needed. These changes should also unlock reusing the same logic for other operations (e.g., DROP COLUMN).

I'm not sure if it's worth pushing this much further given that https://github.com/WordPress/sqlite-database-integration/pull/153 would change the translator quite a bit, and will likely be a chance to re-architect the translator a bit more.

JanJakes avatar Aug 15 '24 13:08 JanJakes

Superseded by #179

adamziel avatar May 30 '25 13:05 adamziel