orion-server 1.8.1

Turn business logic into live REST/Kafka services, declared as JSON
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
//! Column identifiers for every Orion-owned table, as sea-query `Iden`s.
//!
//! # The `_json` suffix is load-bearing
//!
//! Every column here that holds a serialized JSON document is named `*_json`,
//! and every column named `*_json` holds one (D26). It is the only signal a
//! reader gets that the value has to go through `serde_json` before it means
//! anything — the storage type is `text` either way, so nothing else
//! distinguishes `tasks_json` from `name`.
//!
//! `workflows.tags` and `channels.methods` were the two exceptions until 1.0.0
//! and are now `tags_json` / `methods_json`. The wire format is unchanged: the
//! admin API still says `tags` and `methods`, because the DTOs in
//! [`super::models::dto`] name their own fields and are the only types that
//! reach the network.
//!
//! Two tests hold the line: `column_identifiers_are_pinned` in this module,
//! and `json_columns_carry_the_json_suffix` in [`super::models::dto`], which
//! enforces the rule for any column added later.

use sea_query::Iden;

// ============================================================
// Workflows table
// ============================================================

#[derive(Iden)]
pub enum Workflows {
    Table,
    WorkflowId,
    Version,
    Name,
    Description,
    Priority,
    Status,
    RolloutPercentage,
    ConditionJson,
    TasksJson,
    TagsJson,
    LoopJson,
    ContinueOnError,
    CreatedAt,
    UpdatedAt,
}

// ============================================================
// Channels table
// ============================================================

#[derive(Iden)]
pub enum Channels {
    Table,
    ChannelId,
    Version,
    Name,
    Description,
    ChannelType,
    Protocol,
    MethodsJson,
    RoutePattern,
    Topic,
    ConsumerGroup,
    TransportConfigJson,
    WorkflowId,
    ConfigJson,
    Status,
    Priority,
    TagsJson,
    CreatedAt,
    UpdatedAt,
}

// ============================================================
// Connectors table
// ============================================================

#[derive(Iden)]
pub enum Connectors {
    Table,
    Id,
    Name,
    ConnectorType,
    ConfigJson,
    Enabled,
    TagsJson,
    CreatedAt,
    UpdatedAt,
}

// ============================================================
// Connector OAuth2 runtime state (#268)
// ============================================================

#[derive(Iden)]
pub enum ConnectorOauthState {
    Table,
    ConnectorName,
    Fingerprint,
    StateJson,
    UpdatedAt,
}

// ============================================================
// Traces table
// ============================================================

#[derive(Iden)]
pub enum Traces {
    Table,
    Id,
    Channel,
    ChannelId,
    Mode,
    Status,
    InputJson,
    ResultJson,
    ErrorMessage,
    DurationMs,
    StartedAt,
    CompletedAt,
    CreatedAt,
    UpdatedAt,
    TaskTraceJson,
    AccessTokenHash,
}

// ============================================================
// Trace DLQ table
// ============================================================

#[derive(Iden)]
pub enum TraceDlq {
    Table,
    Id,
    TraceId,
    Channel,
    PayloadJson,
    MetadataJson,
    ErrorMessage,
    RetryCount,
    MaxRetries,
    NextRetryAt,
    CreatedAt,
    UpdatedAt,
    ClaimedBy,
    ClaimedUntil,
}

// ============================================================
// Cron scheduling tables
// ============================================================

/// The per-channel cursor: where a schedule has got to.
#[derive(Iden, Clone, Copy)]
pub enum CronScheduleState {
    Table,
    ChannelId,
    ChannelVersion,
    ConfigHash,
    NextFireAt,
    PausedAt,
    UpdatedAt,
}

/// The durable run ledger and work queue.
#[derive(Iden, Clone, Copy)]
pub enum CronOccurrences {
    Table,
    Id,
    ChannelId,
    ChannelName,
    ChannelVersion,
    ExecutingVersion,
    WorkflowId,
    /// Quoted by sea-query on every backend, which matters here: `trigger` is a
    /// reserved word in MySQL.
    Trigger,
    ScheduledFor,
    Status,
    Attempt,
    ClaimedBy,
    ClaimedUntil,
    SingletonKey,
    FencingToken,
    TraceId,
    ErrorMessage,
    StartedAt,
    CompletedAt,
    CreatedAt,
    UpdatedAt,
}

/// One row per held singleton key.
#[derive(Iden, Clone, Copy)]
pub enum CronSingletons {
    Table,
    SingletonKey,
    OccurrenceId,
    Holder,
    FencingToken,
    LeaseUntil,
    UpdatedAt,
}

// ============================================================
// Cluster coordination tables
// ============================================================

#[derive(Iden, Clone, Copy)]
pub enum ConfigEpoch {
    Table,
    Id,
    Epoch,
    /// What the bumping node changed, so a peer can scope its resync.
    EpochScope,
    /// The epoch [`ConfigEpoch::EpochScope`] was written for. A scope is only
    /// trustworthy when this matches [`ConfigEpoch::Epoch`] *and* the reader is
    /// applying that one epoch — see
    /// [`crate::cluster::EpochScope::for_advance`].
    EpochScopeAt,
    BreakerEpoch,
    BreakerKey,
    UpdatedAt,
}

#[derive(Iden)]
pub enum JobLeases {
    Table,
    JobName,
    Holder,
    ExpiresAt,
}

// ============================================================
// Packages table (K14 receipts)
// ============================================================

#[derive(Iden)]
pub enum Packages {
    Table,
    Name,
    Version,
    ContentHash,
    State,
    Principal,
    CreatedAt,
    UpdatedAt,
}

// ============================================================
// Audit Logs table
// ============================================================

#[derive(Iden)]
pub enum AuditLogs {
    Table,
    Id,
    Principal,
    Action,
    ResourceType,
    ResourceId,
    Details,
    CreatedAt,
}

// ============================================================
// Views — retained for the contract phase only
// ============================================================

// §5: no repository reads these any more. `versioned::is_current_version` is
// the "latest version per id" predicate that replaced them, applied to the
// base table, so a new column reaches every reader without a view to recreate
// — the thing that made these expensive on Postgres and MySQL, where a
// `SELECT *` view resolves its column list at CREATE time.
//
// The views themselves stay in the schema for one release: a rolling deploy
// runs the previous binary against this database, and that binary still reads
// them. The migration that drops them is the contract half, and it also
// deletes these two idens.

#[derive(Iden)]
pub enum CurrentWorkflows {
    Table,
}

// ============================================================
// Plugins: the versioned entity, and the content-addressed artifacts
// ============================================================

#[derive(Iden)]
pub enum Plugins {
    Table,
    PluginId,
    Version,
    Status,
    Digest,
    ManifestJson,
    TagsJson,
    /// Optional detached signature over `digest` (`[plugins.trust]`).
    Signature,
    CreatedAt,
    UpdatedAt,
}

/// Component bytes by digest. No `current_*` view and no iden for one: the
/// entity was added after `versioned::is_current_version` replaced the views.
#[derive(Iden)]
pub enum PluginArtifacts {
    Table,
    Digest,
    Bytes,
    Size,
    CreatedAt,
}

// ============================================================
// Models: the versioned entity; its bytes live in a bucket, not here
// ============================================================

#[derive(Iden)]
pub enum Models {
    Table,
    ModelId,
    Version,
    Status,
    Digest,
    ManifestJson,
    /// The artifact reference: `{"connector","key","digest","size"}`.
    ArtifactJson,
    /// The admission verdict — derived, outside the immutability trigger.
    AdmissionJson,
    /// What admission read out of the model — derived, nullable.
    StatsJson,
    TagsJson,
    /// Optional detached signature over `digest`.
    Signature,
    CreatedAt,
    UpdatedAt,
}

#[derive(Iden)]
pub enum CurrentChannels {
    Table,
}

#[cfg(test)]
mod tests {
    use super::*;

    /// The physical column names of the two versioned tables, pinned (D26).
    ///
    /// These identifiers are the only thing standing between a repository and
    /// the database, and they have to move in lockstep with three hand-written
    /// migration sets. Renaming a variant here without shipping
    /// `sqlite/009`, `postgres/013` and `mysql/011` — or the reverse — is a
    /// change no type checks, because a sea-query `Iden` compiles to a string.
    /// So the strings live here, once, and a rename has to be deliberate.
    ///
    /// Two entries changed for 1.0.0 — `tags_json` and `methods_json` (D26).
    /// The rule that put them there is enforced for future columns by
    /// `json_columns_carry_the_json_suffix` in `storage::models::dto`; this
    /// test is what makes a revert of *these two* fail by name.
    ///
    /// The suffix belongs to the column and never to the wire: the fields the
    /// admin API publishes are still `tags` and `methods`, which
    /// `wire_names_survive_the_column_rename` in the integration suite asserts
    /// against a live response.
    #[test]
    fn column_identifiers_are_pinned() {
        let workflows: Vec<String> = [
            Iden::to_string(&Workflows::WorkflowId),
            Iden::to_string(&Workflows::Version),
            Iden::to_string(&Workflows::Name),
            Iden::to_string(&Workflows::Description),
            Iden::to_string(&Workflows::Priority),
            Iden::to_string(&Workflows::Status),
            Iden::to_string(&Workflows::RolloutPercentage),
            Iden::to_string(&Workflows::ConditionJson),
            Iden::to_string(&Workflows::TasksJson),
            Iden::to_string(&Workflows::TagsJson),
            Iden::to_string(&Workflows::LoopJson),
            Iden::to_string(&Workflows::ContinueOnError),
            Iden::to_string(&Workflows::CreatedAt),
            Iden::to_string(&Workflows::UpdatedAt),
        ]
        .to_vec();
        assert_eq!(
            workflows,
            [
                "workflow_id",
                "version",
                "name",
                "description",
                "priority",
                "status",
                "rollout_percentage",
                "condition_json",
                "tasks_json",
                "tags_json",
                "loop_json",
                "continue_on_error",
                "created_at",
                "updated_at",
            ]
        );

        let channels: Vec<String> = [
            Iden::to_string(&Channels::ChannelId),
            Iden::to_string(&Channels::Version),
            Iden::to_string(&Channels::Name),
            Iden::to_string(&Channels::Description),
            Iden::to_string(&Channels::ChannelType),
            Iden::to_string(&Channels::Protocol),
            Iden::to_string(&Channels::MethodsJson),
            Iden::to_string(&Channels::RoutePattern),
            Iden::to_string(&Channels::Topic),
            Iden::to_string(&Channels::ConsumerGroup),
            Iden::to_string(&Channels::TransportConfigJson),
            Iden::to_string(&Channels::WorkflowId),
            Iden::to_string(&Channels::ConfigJson),
            Iden::to_string(&Channels::Status),
            Iden::to_string(&Channels::Priority),
            Iden::to_string(&Channels::TagsJson),
            Iden::to_string(&Channels::CreatedAt),
            Iden::to_string(&Channels::UpdatedAt),
        ]
        .to_vec();
        let occurrences = [
            Iden::to_string(&CronOccurrences::Id),
            Iden::to_string(&CronOccurrences::ChannelId),
            Iden::to_string(&CronOccurrences::ChannelName),
            Iden::to_string(&CronOccurrences::ChannelVersion),
            Iden::to_string(&CronOccurrences::ExecutingVersion),
            Iden::to_string(&CronOccurrences::WorkflowId),
            Iden::to_string(&CronOccurrences::Trigger),
            Iden::to_string(&CronOccurrences::ScheduledFor),
            Iden::to_string(&CronOccurrences::Status),
            Iden::to_string(&CronOccurrences::Attempt),
            Iden::to_string(&CronOccurrences::ClaimedBy),
            Iden::to_string(&CronOccurrences::ClaimedUntil),
            Iden::to_string(&CronOccurrences::SingletonKey),
            Iden::to_string(&CronOccurrences::FencingToken),
            Iden::to_string(&CronOccurrences::TraceId),
            Iden::to_string(&CronOccurrences::ErrorMessage),
            Iden::to_string(&CronOccurrences::StartedAt),
            Iden::to_string(&CronOccurrences::CompletedAt),
            Iden::to_string(&CronOccurrences::CreatedAt),
            Iden::to_string(&CronOccurrences::UpdatedAt),
        ]
        .to_vec();
        assert_eq!(
            occurrences,
            [
                "id",
                "channel_id",
                "channel_name",
                "channel_version",
                "executing_version",
                "workflow_id",
                "trigger",
                "scheduled_for",
                "status",
                "attempt",
                "claimed_by",
                "claimed_until",
                "singleton_key",
                "fencing_token",
                "trace_id",
                "error_message",
                "started_at",
                "completed_at",
                "created_at",
                "updated_at",
            ]
        );

        assert_eq!(
            [
                Iden::to_string(&CronSingletons::SingletonKey),
                Iden::to_string(&CronSingletons::OccurrenceId),
                Iden::to_string(&CronSingletons::Holder),
                Iden::to_string(&CronSingletons::FencingToken),
                Iden::to_string(&CronSingletons::LeaseUntil),
            ]
            .to_vec(),
            [
                "singleton_key",
                "occurrence_id",
                "holder",
                "fencing_token",
                "lease_until",
            ]
        );

        assert_eq!(
            [
                Iden::to_string(&CronScheduleState::ChannelId),
                Iden::to_string(&CronScheduleState::ChannelVersion),
                Iden::to_string(&CronScheduleState::ConfigHash),
                Iden::to_string(&CronScheduleState::NextFireAt),
                Iden::to_string(&CronScheduleState::PausedAt),
            ]
            .to_vec(),
            [
                "channel_id",
                "channel_version",
                "config_hash",
                "next_fire_at",
                "paused_at",
            ]
        );

        // The model columns, in the order the three `models` migrations
        // declare them: every one is spelled by hand in each set, and the
        // two derived columns are the ones the immutability trigger must
        // *not* name.
        assert_eq!(
            [
                Iden::to_string(&Models::ModelId),
                Iden::to_string(&Models::Version),
                Iden::to_string(&Models::Status),
                Iden::to_string(&Models::Digest),
                Iden::to_string(&Models::ManifestJson),
                Iden::to_string(&Models::ArtifactJson),
                Iden::to_string(&Models::AdmissionJson),
                Iden::to_string(&Models::StatsJson),
                Iden::to_string(&Models::TagsJson),
                Iden::to_string(&Models::Signature),
                Iden::to_string(&Models::CreatedAt),
                Iden::to_string(&Models::UpdatedAt),
            ]
            .to_vec(),
            [
                "model_id",
                "version",
                "status",
                "digest",
                "manifest_json",
                "artifact_json",
                "admission_json",
                "stats_json",
                "tags_json",
                "signature",
                "created_at",
                "updated_at",
            ]
        );

        assert_eq!(
            channels,
            [
                "channel_id",
                "version",
                "name",
                "description",
                "channel_type",
                "protocol",
                "methods_json",
                "route_pattern",
                "topic",
                "consumer_group",
                "transport_config_json",
                "workflow_id",
                "config_json",
                "status",
                "priority",
                "tags_json",
                "created_at",
                "updated_at",
            ]
        );
    }
}