nl2data-workflow-postgres 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,90 @@
1
+ """Versioned PostgreSQL schema for the workflow state backend.
2
+
3
+ All tables are created inside one bounded schema (the configured
4
+ ``namespace``), so multiple deployments sharing one database service never
5
+ observe each other's records. Records stay isolated by opaque tenant scope
6
+ namespaces: raw tenant or principal claims are never persisted. Only safe
7
+ serialized snapshots and bounded identity columns are stored - never
8
+ prompts, queries, results, credentials, or provider objects.
9
+
10
+ Migrations are additive and versioned: version ``1`` creates the full
11
+ workflow snapshot, idempotency, lease, and schema-metadata surface. A
12
+ runtime never applies a migration newer than the schema version it supports,
13
+ and a database reporting a newer schema than the runtime supports is rejected
14
+ without modification.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ #: The newest schema version this runtime understands.
20
+ SUPPORTED_SCHEMA_VERSION = 1
21
+
22
+ #: Migration steps keyed by the schema version they produce. Each entry is
23
+ #: applied inside one transaction and only when the persisted version is
24
+ #: exactly ``version - 1``, so a partial deployment can never be guessed at.
25
+ MIGRATIONS: dict[int, tuple[str, ...]] = {
26
+ 1: (
27
+ """
28
+ CREATE TABLE IF NOT EXISTS workflow_states (
29
+ workflow_id TEXT NOT NULL,
30
+ request_id TEXT NOT NULL,
31
+ tenant_scope_fingerprint TEXT,
32
+ scope_namespace TEXT NOT NULL DEFAULT '',
33
+ status TEXT NOT NULL,
34
+ revision BIGINT NOT NULL DEFAULT 1,
35
+ schema_version INTEGER NOT NULL,
36
+ snapshot TEXT NOT NULL,
37
+ created_at TIMESTAMPTZ NOT NULL,
38
+ updated_at TIMESTAMPTZ NOT NULL,
39
+ expires_at TIMESTAMPTZ,
40
+ PRIMARY KEY (scope_namespace, workflow_id)
41
+ )
42
+ """,
43
+ """
44
+ CREATE INDEX IF NOT EXISTS idx_workflow_request
45
+ ON workflow_states (scope_namespace, request_id)
46
+ """,
47
+ """
48
+ CREATE INDEX IF NOT EXISTS idx_workflow_status
49
+ ON workflow_states (status, updated_at)
50
+ """,
51
+ """
52
+ CREATE TABLE IF NOT EXISTS idempotency_records (
53
+ idempotency_key TEXT NOT NULL,
54
+ request_id TEXT NOT NULL,
55
+ tenant_scope_fingerprint TEXT,
56
+ scope_namespace TEXT NOT NULL DEFAULT '',
57
+ workflow_id TEXT NOT NULL,
58
+ status TEXT NOT NULL,
59
+ terminal_outcome_fingerprint TEXT,
60
+ created_at TIMESTAMPTZ NOT NULL,
61
+ updated_at TIMESTAMPTZ NOT NULL,
62
+ expires_at TIMESTAMPTZ,
63
+ PRIMARY KEY (scope_namespace, idempotency_key)
64
+ )
65
+ """,
66
+ """
67
+ CREATE INDEX IF NOT EXISTS idx_idempotency_expiry
68
+ ON idempotency_records (expires_at)
69
+ """,
70
+ """
71
+ CREATE INDEX IF NOT EXISTS idx_idempotency_request
72
+ ON idempotency_records (scope_namespace, request_id)
73
+ """,
74
+ """
75
+ CREATE TABLE IF NOT EXISTS workflow_leases (
76
+ scope_namespace TEXT NOT NULL DEFAULT '',
77
+ workflow_id TEXT NOT NULL,
78
+ owner_id TEXT NOT NULL,
79
+ fencing_token BIGINT NOT NULL,
80
+ expires_at TIMESTAMPTZ NOT NULL,
81
+ updated_at TIMESTAMPTZ NOT NULL,
82
+ PRIMARY KEY (scope_namespace, workflow_id)
83
+ )
84
+ """,
85
+ """
86
+ CREATE INDEX IF NOT EXISTS idx_lease_expiry
87
+ ON workflow_leases (expires_at)
88
+ """,
89
+ ),
90
+ }