aboutsummaryrefslogtreecommitdiff
path: root/migrations/auth/20240506_01_798tW-create-jwt-refresh-tokens-table.py
blob: 049ac6bdea87d5ad9063639c71835e4da89cbcca (plain)
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
"""
Create jwt_refresh_tokens table
"""

from yoyo import step

__depends__ = {'20231011_01_CS8NZ-create-new-inbredset-group-owner-role'}

steps = [
    step(
        """
        CREATE TABLE IF NOT EXISTS jwt_refresh_tokens
        -- Store refresh tokens to verify refresh attempts
        (
          token TEXT NOT NULL,
          client_id TEXT NOT NULL,
          user_id TEXT NOT NULL,
          issued_with TEXT NOT NULL UNIQUE, -- JWT ID of JWT issued along with this refresh token
          issued_at INTEGER NOT NULL,
          expires INTEGER NOT NULL,
          scope TEXT NOT NULL,
          revoked INTEGER CHECK (revoked = 0 or revoked = 1),
          parent_of TEXT UNIQUE,
          PRIMARY KEY(token),
          FOREIGN KEY (client_id) REFERENCES oauth2_clients(client_id)
            ON UPDATE CASCADE ON DELETE RESTRICT,
          FOREIGN KEY (user_id) REFERENCES users(user_id)
            ON UPDATE CASCADE ON DELETE RESTRICT,
          FOREIGN KEY (parent_of) REFERENCES jwt_refresh_tokens(token)
            ON UPDATE CASCADE ON DELETE RESTRICT
        ) WITHOUT ROWID
        """,
        "DROP TABLE IF EXISTS jwt_refresh_tokens")
]