I want to store a secret key encrypted and I want to ensure there is always either none or exactly one entry in this SQLAlchemy model/table. How can this be enforced?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Use some generated content that must be unique. Something like this:
The simplest approach is to create a table with a primary key that has a fixed value with one or more columns to hold singleton values:
The primary key column’s name and type were chosen to be consistent with conventions used by many ORM platforms; e.g., ActiveRecord in Ruby on Rails.
Because
id
has a single, fixed value, it needn’t be referenced in queries.