Now that we have two messages of the day (#202), it is a little awkward to query which of them is disabled. I have to pass in all the known values to the query:
Session.query(NewsletterSetting.value).filter(
NewsletterSetting.account_id == account.id,
NewsletterSetting.value.in_(
[message["disabled_key"] for message in self.all_messages]
),
)
I would rather do:
Session.query(NewsletterSetting.value).filter(
NewsletterSetting.account_id == account.id,
NewsletterSetting.type == "motd-disabled"
),
)
Furthermore, the new setting has nothing to do with the newsletter. I would argue that the old setting also isn't really about the newsletter but about the message of the day. How about instead of specific settings tables we use only one table (e.g. AccountSetting), but with an additional type column to allow specifying what the setting is about?
Something like:
class AccountSetting(model.BaseObject):
__tablename__ = "account_setting"
id = schema.Column(types.Integer(), primary_key=True, autoincrement=True)
account_id = schema.Column(
types.Integer(),
schema.ForeignKey(model.Account.id, onupdate="CASCADE", ondelete="CASCADE"),
nullable=False,
)
type = schema.Column(types.String(512), nullable=False)
value = schema.Column(types.String(512), nullable=False)
This would also allow migrating the newsletter subscriptions to the new table.
AccountSetting(account_id=12345, type="newsletter_subscription", value="fr/bakery/bakery")
AccountSetting(account_id=12345, type="newsletter_subscription", value="fr")
Note that this should probably live in Euphorie instead of osha.oira.
Now that we have two messages of the day (#202), it is a little awkward to query which of them is disabled. I have to pass in all the known values to the query:
I would rather do:
Furthermore, the new setting has nothing to do with the newsletter. I would argue that the old setting also isn't really about the newsletter but about the message of the day. How about instead of specific settings tables we use only one table (e.g. AccountSetting), but with an additional
typecolumn to allow specifying what the setting is about?Something like:
This would also allow migrating the newsletter subscriptions to the new table.
Note that this should probably live in Euphorie instead of osha.oira.