kvesteri / sqlalchemy-utils

Various utility functions and datatypes for SQLAlchemy.
Other
1.27k stars 322 forks source link

Add TextEncryptedType to support large Text columns #730

Open Invincibear opened 9 months ago

Invincibear commented 9 months ago

Based on StringEncryptedType, the only difference is SQLAlchemy treats it as a Text column instead of a String (VARCHAR in MySQL) column, allowing for far larger encrypted text data.

This was made out of necessity when attempting to save encrypted Google OAuth tokens that cause the table size to exceed the max, even though individual columns were acceptable. By storing as TEXT (or BLOB), they are stored separately and other than their metadata, don't count towards the table's max width.

There is already a EncryptedType class using LargeBinary as the type, but it has a deprecation warning and comments warning that in the future it'll be changed to String.