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

Allow other database objects to have their name explicitly specified (eg indexes, foreign keys) #422

Closed
jrouffiac opened this issue Mar 23, 2021 · 5 comments · Fixed by #423
Labels
enhancement A feature that exists, works as intended but needs to be improved

Comments

@jrouffiac
Copy link

Describe the feature as you'd like to see it
Currently, Masonite ORM generates database object names by appending some hard coded values when generating the DDL from the migrations. I need to follow a different pattern to comply with client-specified database naming norms.

For example,
table.string("email").unique() on the users table definition leads to a unique index with the database object name of users_email_unique

I would like to be able to specify a param on unique(), index and foreign which , if present, would be used instead of the auto generated name:

table.unique(column="email", name="uq_users_email")
table.index(column="some_other_field", name="ix_users_some_other_field")
table.foreign(column="user_type_id", name="fk_users_user_type_id").references("id").on("user_types")

etc

Thanks!

@jrouffiac jrouffiac added the enhancement A feature that exists, works as intended but needs to be improved label Mar 23, 2021
@josephmancuso
Copy link
Member

This is done in v1.0.42

@jrouffiac
Copy link
Author

jrouffiac commented Mar 24, 2021

Ho @josephmancuso . Firstly, thanks for doing that so quickly! :)

I've found an issue:

If I use method chaining on the field as it is being created, the index() method expects the column param:

table.integer(column="user_id").unsigned().index(name='ix_profiles_user_id')

Gives:

  TypeError

  index() missing 1 required positional argument: 'column'

If I add the name of the column, it works. But as we are already operating on the column, it should know from context.

@jrouffiac
Copy link
Author

jrouffiac commented Mar 24, 2021

Update: foreign() and fulltext() are also affected but unique() seems to work fine as its column param is optional.

If I create the index or foreign key constraint as a separate statements, these work fine.

Shall i raise a bug report?

@josephmancuso
Copy link
Member

sure

@josephmancuso
Copy link
Member

@SparrowhawkMMU technically this isn't a bug as it wasn't a feature. I think Orator supported this though for indexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants