Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import { type Generated, type GeneratedAlways } from 'kysely';
2
3import { type UserRole } from '../models/types/permissioning.js';
4
5/** Postgres enum for backtests.status (generated column — read-only in app). */
6export type BacktestStatusDb = 'RUNNING' | 'COMPLETE' | 'CANCELED';
7
8/** Postgres enum for users.login_methods. */
9export type LoginMethod = 'password' | 'saml';
10
11export type CoreAppTablesPg = {
12 'public.orgs': {
13 id: string;
14 email: string;
15 name: string;
16 website_url: string;
17 api_key_id: string | null;
18 created_at: Date;
19 updated_at: Date;
20 on_call_alert_email: string | null;
21 };
22 // `id`, `created_at`, `updated_at` are all NOT NULL with no server-side
23 // default — the app supplies them on INSERT, just like the Sequelize model
24 // did. The DB enforces a CHECK constraint (`password_null_when_not_present`)
25 // tying `password IS NOT NULL` to `'password' ∈ login_methods`; that
26 // invariant is enforced at the app layer too (see `userValidation.ts`).
27 'public.users': {
28 id: string;
29 email: string;
30 password: string | null;
31 first_name: string;
32 last_name: string;
33 role: UserRole;
34 approved_by_admin: boolean;
35 rejected_by_admin: boolean;
36 created_at: Date;
37 updated_at: Date;
38 org_id: string;
39 login_methods: LoginMethod[];
40 };
41 'public.location_banks': {
42 id: string;
43 name: string;
44 description: string | null;
45 org_id: string;
46 owner_id: string;
47 created_at: GeneratedAlways<Date>;
48 updated_at: Date;
49 full_places_api_responses: unknown[];
50 };
51 'public.location_bank_locations': {
52 id: string;
53 bank_id: string;
54 geometry: unknown;
55 bounds: unknown | null;
56 name: string | null;
57 google_place_info: unknown | null;
58 created_at: GeneratedAlways<Date>;
59 updated_at: GeneratedAlways<Date>;
60 };
61 'public.backtests': {
62 id: string;
63 rule_id: string;
64 creator_id: string;
65 sample_desired_size: number;
66 sample_actual_size: Generated<number>;
67 sample_start_at: Date;
68 sample_end_at: Date;
69 sampling_complete: Generated<boolean>;
70 content_items_processed: Generated<number>;
71 content_items_matched: Generated<number>;
72 created_at: GeneratedAlways<Date>;
73 updated_at: Date;
74 cancelation_date: Date | null;
75 status: GeneratedAlways<BacktestStatusDb>;
76 };
77 'public.users_and_favorite_rules': {
78 user_id: string;
79 rule_id: string;
80 created_at: GeneratedAlways<Date>;
81 updated_at: Date;
82 };
83};