fizz
fizz copied to clipboard
Add columns with default zero values.
When using add_column to add a column to an existing table, postgres (and I assume other database engines) will return an error when you try to add a non-nullable (default in fizz) column to a table that already contains rows.
This leads to a bit of a footgun in Fizz, because in development/CI, I'll frequently have tables without any rows when running migrations, leading to migration errors when deploying.
I propose changing Fizz to include a default value for columns (that are not configured to be null) to the corresponding Go zero value. I don't see any harm in including these defaults for all columns (even when creating a new table) for consistency. When pop inserts a row, you'll get the zero value on the struct if it's not set, so this behavior is consistent with how Go/Pop behave.
If the default option is provided when creating a column, it would take override this new behavior.
I don't think this would be considered a breaking change. Even though this changes the behavior of Fizz, the new behavior should be compatible with existing workflows.
I agree with the intention. I hope it could be implemented in the next version.