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

Autogeneration should respect the specified naming convention #401

Open
rushilsrivastava opened this issue Aug 27, 2022 · 5 comments
Open

Comments

@rushilsrivastava
Copy link

rushilsrivastava commented Aug 27, 2022

Currently, the autogeneration template of indexes is non configurable:

def _spatial_idx_name(table_name, column_name):
return 'idx_{}_{}'.format(table_name, column_name)

It would be nice to follow the default conventions established in the metadata if specified, so that it can remain consistent with sqlalchemy.

@adrien-berchet
Copy link
Member

Hi @rushilsrivastava !
Thank you for this suggestion, it's a good idea.
I don't have much time to work on this atm so I leave the issue open for now but that's clearly a feature that could be added.

(But if anyone else can work on it it would be nice 😉 )

@adrien-berchet
Copy link
Member

Hi @jjgarrett0, did you have some time to work on this? (just to know, no pressure ☺️ )

@jjgarrett0
Copy link

@adrien-berchet I have not. Life got in the way, I should have some time this October to take a gander at it though.

@adrien-berchet
Copy link
Member

@adrien-berchet I have not. Life got in the way, I should have some time this October to take a gander at it though.

No problem @jjgarrett0, October will be perfect, thanks!

@sdp5
Copy link
Contributor

sdp5 commented Apr 29, 2024

at geoalchemy2/admin/__init__.py#L92 if we replace following

table.append_constraint(
            Index(
                _spatial_idx_name(table.name, column.name),
                col,
                **kwargs,
            )
        )

with

table.append_constraint(
            Index(
                None,
                col,
                **kwargs,
            )
        )

we could achieve the results. However we need to handle cases where we're doing idx.name != _spatial_idx_name(table.name, col.name) in before_create events for multiple dialects.
do we need to save the info about indexes created by geoalchemy?

Another way could be to extract index_naming_convention and format the pattern using SQLAlchemy's naming.ConventionDict .. or something similar

index_convention = naming._get_convention(table.metadata.naming_convention, Index)

get index_constraint from table_orm.constraints

index_name = index_constraint % naming.ConventionDict(
       index_constraint, table_orm, table_orm.metadata.naming_convention
)

but this needs constraint to be present in table_orm at this stage, which is not.

how would you suggest @adrien-berchet ..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants