-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathAutoBeDatabase.ts
More file actions
210 lines (173 loc) · 6.23 KB
/
AutoBeDatabase.ts
File metadata and controls
210 lines (173 loc) · 6.23 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
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
import { tags } from "typia";
import { CamelCasePattern } from "../typings";
import { SnakeCasePattern } from "../typings/SnakeCasePattern";
/**
* AST types for Prisma schema generation via AI function calling.
*
* Hierarchy: IApplication → IFile → IModel → Fields + Indexes.
*
* IMPORTANT: All description fields must be written in English.
*/
export namespace AutoBeDatabase {
/** Root container for the entire database schema. */
export interface IApplication {
/** Array of schema files, each covering a business domain. */
files: IFile[];
}
/** A single Prisma schema file covering one business domain. */
export interface IFile {
/**
* Filename following "schema-{number}-{domain}.prisma" convention. The
* number indicates dependency order.
*/
filename: string & tags.Pattern<"^[a-zA-Z0-9._-]+\\.prisma$">;
/** Business domain namespace used in Prisma @namespace directives. */
namespace: string;
/** Models (database tables) within this domain. */
models: IModel[] & tags.MinItems<1>;
}
/** A single Prisma model (database table). */
export interface IModel {
/** MUST use snake_case. Materialized views use "mv_" prefix. */
name: string & SnakeCasePattern;
/**
* Business purpose of this model.
*
* Format: summary sentence first, `\n\n`, then paragraphs grouped by topic.
* Use `{@\link ModelName}` for cross-references.
*
* > MUST be written in English.
*/
description: string;
/**
* Whether this model is a materialized view (read-only cached query). If
* true, name must use "mv_" prefix.
*/
material: boolean;
/**
* Architectural role of this model, guiding API endpoint generation.
*
* - "primary": Core entity users manage independently (full CRUD APIs). Use
* when users need to create, search, or manage entities outside their
* parent context.
* - "actor": Authenticated user type with its own identity, credentials, and
* auth flow. Generates auth endpoints.
* - "session": Login session table belonging to exactly one actor.
* Append-only audit trail, managed via auth flows.
* - "subsidiary": Supporting entity managed through its parent, rarely needs
* standalone endpoints.
* - "snapshot": Point-in-time versioning record, typically append-only and
* read-only from user perspective.
*/
stance: "primary" | "subsidiary" | "snapshot" | "actor" | "session";
//----
// FIELDS
//----
/** Primary key field (UUID). */
primaryField: IPrimaryField;
/** Foreign key fields establishing relationships to other models. */
foreignFields: IForeignField[];
/** Regular data fields (names, timestamps, flags, amounts, etc.). */
plainFields: IPlainField[];
//----
// INDEXES
//----
/** Unique indexes for data integrity constraints. */
uniqueIndexes: IUniqueIndex[];
/** Regular indexes for query performance. */
plainIndexes: IPlainIndex[];
/** GIN indexes for PostgreSQL full-text search (trigram). */
ginIndexes: IGinIndex[];
}
/** Primary key field of a model. */
export interface IPrimaryField {
/** MUST use snake_case. */
name: string & SnakeCasePattern;
type: "uuid";
/** Business purpose of this primary key. MUST be written in English. */
description: string;
/**
* @ignore
* @internal
*/
nullable?: boolean;
}
/** Foreign key field establishing a relationship to another model. */
export interface IForeignField {
/** MUST use snake_case. Convention: "{target_model}_id". */
name: string & SnakeCasePattern;
type: "uuid";
/**
* Describe the relationship purpose and semantics of this foreign key.
*
* Format: summary sentence first, `\n\n`, then paragraphs grouped by topic.
* Use `{@\link ModelName}` for cross-references.
*
* > MUST be written in English.
*/
description: string;
/** Prisma relation configuration. */
relation: IRelation;
/** True for 1:1 relationships, false for 1:N. */
unique: boolean;
/** True if the relationship is optional. */
nullable: boolean;
}
/** Prisma @relation configuration for a foreign key. */
export interface IRelation {
/** Relation property name in this model. MUST use camelCase. */
name: string & CamelCasePattern;
/** Must match an existing model name in the schema. */
targetModel: string;
/**
* Inverse relation property name generated in the target model. Typically
* plural for 1:N (e.g., "comments"), singular for 1:1.
*/
oppositeName: string & CamelCasePattern;
/**
* Explicit Prisma mapping name. Only needed for self-referential relations
* or when auto-generated names conflict.
*
* @internal
*/
mappingName?: string;
}
/** A regular data field (not a primary or foreign key). */
export interface IPlainField {
/** MUST use snake_case. */
name: string & SnakeCasePattern;
/**
* Prisma/PostgreSQL type mapping: boolean, int, double, string, uri, uuid
* (non-FK), datetime.
*/
type: "boolean" | "int" | "double" | "string" | "uri" | "uuid" | "datetime";
/**
* Business purpose of this field.
*
* Format: summary sentence first, `\n\n`, then paragraphs grouped by topic.
* Use `{@\link ModelName}` for cross-references.
*
* > MUST be written in English.
*/
description: string;
/** Whether this field can be null. */
nullable: boolean;
}
/** Unique index constraint (@@unique). */
export interface IUniqueIndex {
/** Field names forming the unique constraint. All must exist in the model. */
fieldNames: string[] & tags.MinItems<1> & tags.UniqueItems;
/** Always true. Distinguishes from plain indexes. */
unique: true;
}
/** Regular index for query performance (@@index). */
export interface IPlainIndex {
/** Field names to index. Order matters for composite indexes. */
fieldNames: string[] & tags.MinItems<1> & tags.UniqueItems;
}
/** GIN index for PostgreSQL full-text search (gin_trgm_ops). */
export interface IGinIndex {
/** Must be a string field containing searchable text. */
fieldName: string;
}
}