Skip to content

Use server_default for deleted column

Jeremiah Bonney requested to merge jbonney/server_default into master

Description

When trying to upgrade an existing postgres database from the previous revision e287a533bbd7 to the new revision 69ceb5938c06, the generated sql looked like this:

ALTER TABLE index ADD COLUMN deleted BOOLEAN NOT NULL;

Running this on a database with entries in the index causes this error:

ERROR: column "deleted" contains null values

https://stackoverflow.com/a/55277893 brings up this point, but I've personally found the documentation to be very lacking unfortunately :/

This MR switches to using server_default, which seems to handle this as I would personally expect. It generates the following SQL: ALTER TABLE index ADD COLUMN deleted BOOLEAN DEFAULT false NOT NULL;

Since server_default doesn't handle driver differences like default seems to, this leverages sqlalchemy's false() function, which provides a false value for the driver you're using. So this should work with sqlite, although I had trouble getting the specific alembic commands needed to confirm it 100%.

I'm not sure how correct it is to modify the alembic revision in place like this, I'm not an expert at this stuff at all. So I'd love some feedback!

Merge request reports