Skip to content

Instantly share code, notes, and snippets.

@MagnusOxlund
MagnusOxlund / peewee_two_mysql_users_least_privilege.py
Last active February 3, 2024 08:28
Using Peewee with two (or more) MySQL users to implement principle of least privilege
# Naive approach:
# 1. Create two MySQLDatabase instances for the same MySQL database:
# * One instantiated with your CRUD-privileged user
# * One instantiated with your DDL-privileged user
#
# 2. Next, define your test model with `database=crud_instance` in
# its Meta subclass.
#
# 3. Then establish a database connection from the ddl_instance and
# issue `create_tables()`.