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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//! `Org` — the registry-level tenant record.
//!
//! Lives in the **registry database** (the one configured at boot via
//! `RUSTANGO_REGISTRY_URL`). Every other database the application
//! reaches is discovered through this table. Adding a tenant is
//! `INSERT INTO rustango_orgs (...)`, no config edit and no restart.
//!
//! ## Fields and what they mean
//!
//! | Field | Purpose |
//! |------------------|-------------------------------------------------------------|
//! | `id` | Server-assigned PK (`Auto<i64>` → `BIGSERIAL`). |
//! | `slug` | Globally-unique URL-safe handle (e.g. `"acme"`). |
//! | `display_name` | Human-friendly label for the admin UI. |
//! | `storage_mode` | `"schema"` (in the registry DB) or `"database"` (dedicated).|
//! | `database_url` | Secret reference (`vault://...`/`env://...`/literal URL). |
//! | `schema_name` | Per-tenant schema in `"schema"` mode (defaults to `slug`). |
//! | `host_pattern` | `Host` header to match (e.g. `"acme.app.com"`). |
//! | `port` | Incoming port to match for port-based routing. |
//! | `path_prefix` | URL path prefix (e.g. `"/acme"`) — opt-in, null by default. |
//! | `active` | Soft-disable without dropping data. |
//! | `created_at` | Set on insert. |
//!
//! ## What's missing in Slice 1
//!
//! * `slug` carries `#[rustango(unique)]` so the DDL writer emits the
//! `UNIQUE` constraint inline; the bootstrap migration uses a plain
//! `CreateTable` op with no separate `DataOp`.
//! * `storage_mode` is a raw `String` because rustango models can't
//! carry custom enums yet. The [`StorageMode`] helper enum in this
//! module wraps the conversion.
//! * `database_url` carries plaintext for now. v0.5 Slice 3.5 adds the
//! `SecretsResolver` indirection so the value can be a vault
//! reference instead of a literal URL.
use crateModel;
/// Registry record describing one tenant.
///
/// `#[derive(Model)]` registers it in the inventory, so any binary
/// linking `rustango-tenancy` automatically picks up the table when
/// `migrate::apply_all` walks the registry — or via
/// `make_migrations` against the registry DB.
// Slices 2+ wire these fields into resolvers / pools / migrations.
/// Convenience enum for [`Org::storage_mode`]. The model field stays
/// a raw `String` because rustango doesn't yet carry custom enums in
/// the schema layer; this wrapper bridges to/from `&str`.
///
/// ```
/// use rustango::tenancy::StorageMode;
/// assert_eq!(StorageMode::Schema.as_str(), "schema");
/// assert_eq!(StorageMode::Database.as_str(), "database");
/// assert_eq!(StorageMode::parse("schema").unwrap(), StorageMode::Schema);
/// ```