@pylonsync/sdk 0.3.47 → 0.3.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +27 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -114,6 +114,30 @@ export interface IndexDefinition {
|
|
|
114
114
|
name: string;
|
|
115
115
|
fields: string[];
|
|
116
116
|
unique: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Optional SQL predicate. When set, the framework emits a *partial*
|
|
119
|
+
* index — `CREATE [UNIQUE] INDEX … WHERE <predicate>` — so the index
|
|
120
|
+
* (and any uniqueness constraint) only applies to rows matching the
|
|
121
|
+
* predicate.
|
|
122
|
+
*
|
|
123
|
+
* Use case: enforce "max 1 hobby-tier org per user" without breaking
|
|
124
|
+
* paid users who legitimately own many orgs:
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* indexes: [{
|
|
128
|
+
* name: "uniq_hobby_owner",
|
|
129
|
+
* fields: ["createdBy"],
|
|
130
|
+
* unique: true,
|
|
131
|
+
* where: "plan = 'hobby'",
|
|
132
|
+
* }]
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* The predicate is passed straight through to the database. Both
|
|
136
|
+
* SQLite and Postgres accept this syntax — write SQL the underlying
|
|
137
|
+
* engine understands. Pylon does NOT validate or escape this string,
|
|
138
|
+
* so DO NOT interpolate user input here.
|
|
139
|
+
*/
|
|
140
|
+
where?: string;
|
|
117
141
|
}
|
|
118
142
|
|
|
119
143
|
export interface RelationDefinition {
|
|
@@ -294,6 +318,8 @@ export interface ManifestIndex {
|
|
|
294
318
|
name: string;
|
|
295
319
|
fields: string[];
|
|
296
320
|
unique: boolean;
|
|
321
|
+
/** Optional partial-index predicate — see `IndexDefinition.where`. */
|
|
322
|
+
where?: string;
|
|
297
323
|
}
|
|
298
324
|
|
|
299
325
|
export interface ManifestRelation {
|
|
@@ -394,6 +420,7 @@ export function entitiesToManifest(
|
|
|
394
420
|
name: idx.name,
|
|
395
421
|
fields: idx.fields,
|
|
396
422
|
unique: idx.unique,
|
|
423
|
+
...(idx.where ? { where: idx.where } : {}),
|
|
397
424
|
})),
|
|
398
425
|
};
|
|
399
426
|
if (e.relations && e.relations.length > 0) {
|