Is there a way to grant permissions when creating a new table using sqlalchemy? The only way I see to do it now is to execute an sql "GRANT ALL ON TABLE blabla to whomever;" everytime I do a Base.metadata.create_all(...)
I use PostgreSQL database with psycopg2 backend. After create_all
I execute:
import models
from psycopg2 import sql
for table in models.Base.metadata.tables.values():
connection.connection.cursor().execute(
sql.SQL('GRANT ALL PRIVILEGES ON {} TO {}').format(
sql.Identifier(table.name), sql.Identifier('bob')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With