Repository navigation
Expand file tree
/
Copy pathSchemaTableClasses.cs
More file actions
56 lines (48 loc) · 3.01 KB
/
Copy pathSchemaTableClasses.cs
File metadata and controls
56 lines (48 loc) · 3.01 KB
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
using System.Data.Common;
using FluentAssertions;
namespace LearnStack.Tests.Integration.Database;
/// <summary>ADR-0047's closed applied-table classes; discovery always comes from pg_catalog.</summary>
internal static class SchemaTableClasses
{
public const long SelectDenied = -1;
public static readonly string[] Vendor =
[
"aggregatedcounter", "counter", "hash", "job", "jobparameter", "jobqueue",
"list", "lock", "schema", "server", "set", "state",
];
public static readonly string[] Control = ["background_job_recurrences", "background_job_occurrences"];
public static readonly string[] JobTenant =
[
"background_jobs", "background_job_attempts", "background_job_capacity",
"background_job_reservations", "background_job_recipients",
];
public static readonly string[] Existing =
[
"tenants", "organizations", "tenant_domains", "tenant_locales", "tenant_settings", "tenant_feature_flags",
"platform_entitlement_cache", "platform_host_to_tenant", "outbox_messages", "idempotency_keys",
"event_deliveries", "inbox_messages", "tenant_content_types", "tenant_level_taxonomies",
"tenant_level_taxonomy_items", "customization_generations", "audit_log", "audit_config",
"platform_killswitches", "courses", "lessons", "course_translations", "lesson_translations",
];
public static readonly string[] GlobalIdentity = ["users"];
public static readonly string[] IdentityPlatform = ["identity_authority", "identity_creation_capacity"];
public static readonly string[] IdentityContextual = ["memberships", "membership_profiles",
"membership_role_assignments", "roles", "role_permission_grants", "invitations"];
public static readonly string[] InvitationProvider = ["invitation_email_envelopes", "invitation_email_attempt_receipts"];
public static readonly string[] Data = [.. Existing, .. JobTenant, .. Control, .. Vendor,
.. GlobalIdentity, .. IdentityPlatform, .. IdentityContextual, .. InvitationProvider];
public static bool AppSelectDenied(string table) => Control.Contains(table) || Vendor.Contains(table)
|| table == "identity_creation_capacity" || InvitationProvider.Contains(table);
internal static Task<List<string>> ReadAsync(DbConnection connection, DbTransaction? transaction = null) =>
SchemaQueries.ReadStringsAsync(connection, """
SELECT relname FROM pg_class
WHERE relnamespace = 'public'::regnamespace AND relkind IN ('r', 'p', 'm') ORDER BY relname
""", transaction);
public static async Task AssertCompleteAsync(DbConnection connection, DbTransaction? transaction = null)
{
var discovered = await ReadAsync(connection, transaction);
discovered.Should().BeEquivalentTo(Data.Concat(MigrationChains.HistoryTables),
"every public table must have an exact reviewed class, including the six history tables; "
+ "Fix: classify a new table under Standards 05 rather than excluding it from discovery");
}
}