Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add columns with default zero values. #102

Open
duckbrain opened this issue Oct 30, 2020 · 1 comment
Open

Add columns with default zero values. #102

duckbrain opened this issue Oct 30, 2020 · 1 comment
Labels
enhancement New feature or request s: accepted was accepted or confirmed
Milestone

Comments

@duckbrain
Copy link
Contributor

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.

@sio4 sio4 added this to the v1 / cleanup milestone Sep 7, 2022
@sio4 sio4 added the s: triage label Sep 7, 2022
@sio4 sio4 modified the milestones: v1 / cleanup, v2 Sep 15, 2022
@sio4 sio4 added s: accepted was accepted or confirmed enhancement New feature or request and removed s: triage labels Sep 15, 2022
@sio4
Copy link
Member

sio4 commented Sep 15, 2022

I agree with the intention. I hope it could be implemented in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request s: accepted was accepted or confirmed
Projects
None yet
Development

No branches or pull requests

2 participants