aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/e5f6a7b8c9d0_add_mail_quota.py
blob: c729de4a16db36cd9c5d0e6f71c6d79d8eab5162 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""add mail_quota

The hub's outbound mail allowance, kept across restarts. It lived in two
dicts in `mail.py`, so every deploy handed out a fresh budget — and the hub is
deployed often. A bound a restart forgets is not a bound.

Revision ID: e5f6a7b8c9d0
Revises: d4e5f6a7b8c9
"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "e5f6a7b8c9d0"
down_revision: str | Sequence[str] | None = "d4e5f6a7b8c9"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.create_table(
        "mail_quota",
        sa.Column("key", sa.String(64), primary_key=True),
        sa.Column("window_start", sa.DateTime(timezone=True), nullable=False),
        sa.Column("count", sa.Integer(), nullable=False, server_default="0"),
        sa.Column("last_sent", sa.DateTime(timezone=True), nullable=True),
    )


def downgrade() -> None:
    # Dropping this returns the hub to sending with no recorded history, not to
    # sending without a bound: the limits themselves live in `hub_settings` and
    # in the configuration file.
    op.drop_table("mail_quota")