saffier icon indicating copy to clipboard operation
saffier copied to clipboard

refactor: check that the user-defined table has 1 and only 1 primary …

Open vvanglro opened this issue 1 year ago • 7 comments

Close #123 .

vvanglro avatar Jan 17 '24 08:01 vvanglro

@tarsil Like this?

vvanglro avatar Jan 17 '24 08:01 vvanglro

Ok, I think I understand what is happening here. I will have a look later. Thank you for submitting the PR @vvanglro 👍🏼

tarsil avatar Jan 17 '24 09:01 tarsil

@vvanglro although your change is great my concern is for the people already using Saffier as this will break the existing codebase.

The purpose of automatically generate the primary key is for you not to worry about declaring it. Pretty much like Django does and this change will force everyone to add an ID into the existing codebase.

tarsil avatar Jan 17 '24 09:01 tarsil

My suggestion would be to release this change as a larger release. For example v1.4.0 or v2.0.0

vvanglro avatar Jan 17 '24 09:01 vvanglro

I need to think about this honestly since this can cause a world of trouble and people can simply stop using it because of it. Very unlikely but it’s a possibility.

Another thing that should be added if we proceed with this step is to add a warning or several in the docs explaining that prior to version 2.0.0 (not v2.0.0), the ID was automatically added by Saffier but from the release 2.0.0 that will be managed by the user providing more control and freedom over the primary keys.

This should probably be included in this PR too.

Something like this if this make sense?

tarsil avatar Jan 17 '24 09:01 tarsil

Yes, this also fixes the bug that would report multiple primary keys if the user-defined primary key field had a name other than id.

You can add deprecated auto-add primary key field warnings to subsequent 1.x releases to transition to version 2.x. Until you think you can release 2.0.

vvanglro avatar Jan 17 '24 09:01 vvanglro

Yes, this also fixes the bug that would report multiple primary keys if the user-defined primary key field had a name other than id.

You can add deprecated auto-add primary key field warnings to subsequent 1.x releases to transition to version 2.x. Until you think you can release 2.0.

The deprecation warning should definitely be added but the AutoMixin happens when the ID is an integer.

@vvanglro what I would love to see it tested here since you changed is some tests proving that you can add different primary keys with different names and types (based on what you are trying to solve)?

If that is ok and passing + current tests, then I will proceed with initial pre-releases of Saffier with the warnings before merging this and do the big release.

tarsil avatar Jan 17 '24 09:01 tarsil