colopl / laravel-spanner

Laravel database driver for Google Cloud Spanner
Apache License 2.0
97 stars 16 forks source link

Composite Keys #147

Open matthewjumpsoffbuildings opened 11 months ago

matthewjumpsoffbuildings commented 11 months ago

When at scale, Spanner docs often suggest using composite keys for the primary key, for example using a ShardId combined with the other columns, something like PRIMARY KEY (ShardId, Id)

Is there already a proper way to do this using this driver? And to handle things like many-to-many relationships with composite primary keys etc?

I see there is an existing library for composite keys in Eloquent in general, https://github.com/thiagoprz/eloquent-composite-key - is that compatible with this driver perhaps?

taka-oyama commented 11 months ago

Is there already a proper way to do this using this driver?

No, you will have to add the constraints manually.

taka-oyama commented 11 months ago

I see there is an existing library for composite keys in Eloquent in general, https://github.com/thiagoprz/eloquent-composite-key - is that compatible with this driver perhaps?

You can try, but I don't think that trait covers complex cases like relations.

b141568 commented 10 months ago

We use this library too. Laravel does not seem to support composite keys in certain circumstances. Laravel only identifies data with the primaryKey type "string". But when using the library https://github.com/thiagoprz/eloquent-composite-key, it identifies string or array as primary key

For complex relationships we use https://github.com/tylernathanreed/laravel-composite-relations

taka-oyama commented 9 months ago

But when using the library https://github.com/thiagoprz/eloquent-composite-key, it identifies string or array as primary key

That is not aligned with how laravel does things and may result in errors where string is expected to return from$model->getKey() so it may make upgrading to newer versions hard and painful.

For complex relationships we use https://github.com/tylernathanreed/laravel-composite-relations.

This overrides a lot of the logic from the base framework and that's quite risky when upgrading the underlying framework.