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

it's possible to change the table name for user/role/permission tables? #2158

Open
ZeeD opened this issue Nov 6, 2023 · 2 comments
Open

Comments

@ZeeD
Copy link

ZeeD commented Nov 6, 2023

By default the models/tables defined in flask_appbuilder/security/sqla/models.py have the ab_ prefix

I am trying to extend the data model (adding some columns) with a subclass - as suggested in Extending the User Model - but I also would like to change the table names, so ab_user will became users.

It's possible? if I naively set

class MyUser(User):
    __tablename__ = 'users'
    ...

I end with sqlalchemy.exc.ArgumentError: Can't place __table_args__ on an inherited class with no table. during the import of the module

@Yoyasp
Copy link
Contributor

Yoyasp commented Dec 20, 2023

What are you trying to accomplish?
Do you want the entire user table to have a different name, or are you trying to store only your custom columns in a different table?

If you want to change the table name of the User class you would have to change it in the source code and rebuild from scratch. as the User class is used internally. I think theoraticly you could make an edit to the class that allows polymorphism (like here). But im not quite sure how it works and seems like a lot of trouble.

If you want to create a new table that only holds your custom columns, I would suggest creating your own class and making a 1-to-1 mapping to the User class.

However im still not really understanding why you would want to change the table name....

@ZeeD
Copy link
Author

ZeeD commented Dec 22, 2023

I want the entire user table to have a different name, while keeping the logic already there.
AND I also want to extend the table adding some columns, but that's another thing.
But I really don't want to vendor the project, so I think I would try to change the class dynamically

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

No branches or pull requests

2 participants