-
Notifications
You must be signed in to change notification settings - Fork 51
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
[FEAT] static layers extra tables unique names #1445
Conversation
pick unique name by trailing sequences if table name already exists - table name like: file_name -> file_name_1 -> file_name_2
pass | ||
async def list_static_layer_table_names(self, db: AsyncSession, name_like=""): | ||
metadata_obj = MetaData(schema="information_schema") | ||
tables = Table( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very elegant solution to avoid SQL-string. I did not know this works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @EPajares . Also while searching about functions I found that we can use SqlAlechemy func
method to call the functions (ref). So we can use it to have user defined functions also as SqlAlchemy Query object and use it's other methods cleaner.
From doc:
Note that any name not known to func generates the function name as is - there is no restriction on what SQL functions can be called, known or unknown to SQLAlchemy, built-in or user defined. The section here only describes those functions where SQLAlchemy already knows what argument and return types are in use.
db=db, name_like=name | ||
) | ||
counter = 1 | ||
while name in static_layer_table_names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking again about this logic and I think it could break in the following scenario.
Imagine you have:
table1
table2
table3
And now you delete table2. You will have two tables and the counter will be two. Accordingly it will assign 3 for table3
. But table3
is already taken and we will run into duplicated table name. Maybe we could get the max counter and then assign max + 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it won't. Because it will be checked again at while
part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. So we should be fine with this.
for crud_static_layer.list_static_layer_table_names()
pick unique name by trailing sequences if table name already exists
Related issue
#1427