[Todo] How to set primary and foreign key name

0 votes
asked Oct 2, 2019 in Feature Request by cent89 (200 points)
recategorized Oct 2, 2019 by ludek.vodicka

Hi,
how I can set a custom name for the primary key name?
With Laravel, I can do this:

$table->primary(['centrodilavoro_id','lavorazione_id'], 'CUSTOM_NAME);

Thanks!
Roberto

1 Answer

0 votes
answered Oct 2, 2019 by ludek.vodicka Skipper developer (140,450 points)

Hello Roberto,

currently there are only two modes of how PK/FK names are generated. Automatically by Laravel or automatically with predefined UUID values by Skipper.

You can switch for the second mode in project settings:
enter image description here

UUID-like PK/FK names are here because Laravel sometimes generates too long name which causing DB errors, so we decided to solve it via automatically generated uuids on Skipper side.

But is there any reason to allow also custom PK/FK names? What is the use case for such a feature?

Thanks!

commented Oct 2, 2019 by cent89 (200 points)

Hi,
thanks for the answer.
The issue is due to Laravel generations of the name, that sometimes as too long, with DB errors.
The generated names is a good solution to avoid DB errors during migration, but the names as little understanding.

Thanks!

commented Oct 2, 2019 by ludek.vodicka Skipper developer (140,450 points)

Can you please be more specific about what you mean by "but the names as little understanding." ?

Does it mean that auto-generated names in current for are sufficient for you or you need human-readable names FK/PK names in the database?

commented Oct 2, 2019 by cent89 (200 points)

Exactly, the auto-generated names are not human-readble.
In this example, the key name are not related to the field key.

$table->primary(['centrodilavoro_id','lavorazione_id'], 'IX_2cd618e7de18454f9bd2f26ac47e3dfd');

commented Oct 2, 2019 by ludek.vodicka Skipper developer (140,450 points)

ok, so what you need is per-index and per-foreign key custom name configuration.

I believe we will be able to implement it. Custom per-object names will have priority over default/uuid-like names.

commented Oct 28, 2019 by ludek.vodicka Skipper developer (140,450 points)

Checking this feature but we're not sure how to implement it correctly. There is an issue with single-column primary keys.

Currently, we're exporting it as:

$table->bigInteger('id')->autoIncrement()->unsigned();

but there is no way how to pass the custom index to such a definition. On the other side, when we define index as $table->primary() there is no way how to set it as autoincrement.

Can you please send me details about how you're configuring such indexes?

...