@tailor-platform/sdk 1.44.2 → 1.45.0
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/CHANGELOG.md +12 -0
- package/dist/{actor-DzCuoMlP.d.mts → actor-CzX_hVOP.d.mts} +2 -2
- package/dist/{application-7wtQzifE.mjs → application-BsSJZRCq.mjs} +3 -2
- package/dist/{application-7wtQzifE.mjs.map → application-BsSJZRCq.mjs.map} +1 -1
- package/dist/application-C0O80PUX.mjs +4 -0
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/lib.d.mts +6 -6
- package/dist/cli/lib.mjs +2 -2
- package/dist/configure/index.d.mts +5 -5
- package/dist/configure/index.mjs +16 -4
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{index-DdsUV-aA.d.mts → index-Bd-0JRjy.d.mts} +2 -2
- package/dist/{index-ZZYEd_0R.d.mts → index-C_f357K2.d.mts} +2 -2
- package/dist/{index-BOfTiouP.d.mts → index-CemBzf4z.d.mts} +41 -8
- package/dist/{index-BEEL1-6Z.d.mts → index-DIz-15Cx.d.mts} +2 -2
- package/dist/{index-0Dk-fDWi.d.mts → index-SnYVi8ww.d.mts} +2 -2
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
- package/dist/plugin/builtin/seed/index.d.mts +1 -1
- package/dist/plugin/index.d.mts +2 -2
- package/dist/{runtime-CEj_sAfP.mjs → runtime-Bmq4L9pj.mjs} +71 -25
- package/dist/runtime-Bmq4L9pj.mjs.map +1 -0
- package/dist/{tailor-db-field-D_z185oq.d.mts → tailor-db-field-CY1D1PtT.d.mts} +5 -2
- package/dist/utils/test/index.d.mts +3 -3
- package/dist/{workflow.generated-B7Mupf5V.d.mts → workflow.generated--YammZcl.d.mts} +2 -2
- package/docs/cli/tailordb.md +35 -415
- package/docs/services/executor.md +15 -1
- package/docs/services/idp.md +2 -2
- package/docs/services/tailordb-migration.md +418 -0
- package/docs/services/tailordb.md +6 -0
- package/package.json +3 -3
- package/dist/application-P55ZFKHG.mjs +0 -4
- package/dist/runtime-CEj_sAfP.mjs.map +0 -1
|
@@ -356,7 +356,8 @@ type IncomingWebhookTrigger = {
|
|
|
356
356
|
};
|
|
357
357
|
type IdpUserTrigger = {
|
|
358
358
|
/** IdP user event trigger */kind: "idpUser"; /** IdP user event types to trigger on */
|
|
359
|
-
events: ("idp.user.created" | "idp.user.updated" | "idp.user.deleted")[];
|
|
359
|
+
events: ("idp.user.created" | "idp.user.updated" | "idp.user.deleted")[]; /** IdP namespace name to subscribe to. If omitted, the project's only IdP is used; throws when multiple IdPs exist. */
|
|
360
|
+
idp?: string | undefined;
|
|
360
361
|
};
|
|
361
362
|
type AuthAccessTokenTrigger = {
|
|
362
363
|
/** Auth access token event trigger */kind: "authAccessToken"; /** Auth access token event types to trigger on */
|
|
@@ -426,6 +427,7 @@ type ExecutorInput = {
|
|
|
426
427
|
} | {
|
|
427
428
|
kind: "idpUser";
|
|
428
429
|
events: ("idp.user.created" | "idp.user.updated" | "idp.user.deleted")[];
|
|
430
|
+
idp?: string | undefined;
|
|
429
431
|
} | {
|
|
430
432
|
kind: "authAccessToken";
|
|
431
433
|
events: ("auth.access_token.issued" | "auth.access_token.refreshed" | "auth.access_token.revoked")[];
|
|
@@ -459,6 +461,7 @@ type Executor = {
|
|
|
459
461
|
} | {
|
|
460
462
|
kind: "idpUser";
|
|
461
463
|
events: ("idp.user.created" | "idp.user.updated" | "idp.user.deleted")[];
|
|
464
|
+
idp?: string | undefined;
|
|
462
465
|
} | {
|
|
463
466
|
kind: "authAccessToken";
|
|
464
467
|
events: ("auth.access_token.issued" | "auth.access_token.refreshed" | "auth.access_token.revoked")[];
|
|
@@ -1628,4 +1631,4 @@ type TailorAnyDBType = TailorDBType<any, any>;
|
|
|
1628
1631
|
type TailorDBInstance<Fields extends Record<string, TailorAnyDBField> = any, User extends object = InferredAttributeMap> = TailorDBType<Fields, User>;
|
|
1629
1632
|
//#endregion
|
|
1630
1633
|
export { ResolverInput as $, RelationType as A, FieldMetadata as At, BeforeLoginHookArgs as B, InferredAttributeMap as Bt, ResolverReadyContext as C, SCIMAuthorization as Ct, DefinedDBFieldMetadata as D, ArrayFieldOutput as Dt, DBFieldMetadata as E, TenantProvider as Et, AuthConfig as F, FieldValidateInput as Ft, UserAttributeListKey as G, JsonCompatible as Gt, OAuth2ClientGrantType as H, TailorUser as Ht, AuthConnectionTokenResult as I, Validators as It, ValueOperand as J, output as Jt, UserAttributeMap as K, JsonValue as Kt, AuthExternalConfig as L, AttributeList as Lt, TailorDBServiceInput as M, FieldOutput$1 as Mt, TailorDBType$1 as N, TailorFieldType as Nt, GqlOperationsConfig as O, DefinedFieldMetadata as Ot, TypeSourceInfoEntry as P, TailorToTs as Pt, Resolver as Q, AuthOwnConfig as R, AttributeMap as Rt, ResolverNamespaceData as S, SCIMAttributeMapping as St, TailorDBReadyContext as T, SCIMResource as Tt, SCIMAttributeType as U, unauthenticatedTailorUser as Ut, DefinedAuth as V, TailorInvoker as Vt, UserAttributeKey as W, InferFieldsOutput as Wt, AuthConnectionConfig as X, TailorField as Y, AuthConnectionOAuth2Config as Z, PluginProcessContext as _, IdProvider as _t, NamespacePluginOutput as a, FunctionOperation as at, ExecutorReadyContext as b, SAML as bt, PluginConfigs as c, IncomingWebhookTrigger as ct, PluginGeneratedExecutor as d, TailorDBTrigger as dt, GeneratorConfig as et, PluginGeneratedExecutorWithFile as f, WebhookOperation as ft, PluginOutput as g, IDToken as gt, PluginNamespaceProcessContext as h, BuiltinIdP as ht, TailorDBType as i, ExecutorInput as it, SerialConfig as j, FieldOptions as jt, IndexDef as k, EnumValue as kt, PluginExecutorContext as l, ResolverExecutedTrigger as lt, PluginGeneratedType as m, AuthInvoker as mt, TailorAnyDBType as n, AuthAccessTokenTrigger as nt, Plugin as o, GqlOperation as ot, PluginGeneratedResolver as p, WorkflowOperation as pt, UsernameFieldKey as q, Prettify as qt, TailorDBField as r, Executor as rt, PluginAttachment as s, IdpUserTrigger as st, TailorAnyDBField as t, BaseGeneratorConfig as tt, PluginExecutorContextBase as u, ScheduleTriggerInput as ut, TailorDBTypeForPlugin as v, OAuth2ClientInput as vt, TailorDBNamespaceData as w, SCIMConfig as wt, GeneratorResult as x, SCIMAttribute as xt, TypePluginOutput as y, OIDC as yt, AuthServiceInput as z, InferredAttributeList as zt };
|
|
1631
|
-
//# sourceMappingURL=tailor-db-field-
|
|
1634
|
+
//# sourceMappingURL=tailor-db-field-CY1D1PtT.d.mts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import { Vt as TailorInvoker } from "../../tailor-db-field-
|
|
3
|
-
import { O as TailorDBType } from "../../workflow.generated
|
|
4
|
-
import { dt as WORKFLOW_TEST_ENV_KEY, n as output,
|
|
2
|
+
import { Vt as TailorInvoker } from "../../tailor-db-field-CY1D1PtT.mjs";
|
|
3
|
+
import { O as TailorDBType } from "../../workflow.generated--YammZcl.mjs";
|
|
4
|
+
import { dt as WORKFLOW_TEST_ENV_KEY, n as output, xt as TailorField } from "../../index-CemBzf4z.mjs";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/test/mock.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import { A as RelationType, Bt as InferredAttributeMap, D as DefinedDBFieldMetadata, Dt as ArrayFieldOutput, E as DBFieldMetadata, F as AuthConfig, Ft as FieldValidateInput, Ht as TailorUser, It as Validators, Jt as output, M as TailorDBServiceInput, Mt as FieldOutput, O as GqlOperationsConfig, Pt as TailorToTs, Wt as InferFieldsOutput, Y as TailorField, c as PluginConfigs, ht as BuiltinIdP, i as TailorDBType$1, j as SerialConfig, jt as FieldOptions, k as IndexDef, kt as EnumValue, qt as Prettify, r as TailorDBField$1, t as TailorAnyDBField$1 } from "./tailor-db-field-
|
|
2
|
+
import { A as RelationType, Bt as InferredAttributeMap, D as DefinedDBFieldMetadata, Dt as ArrayFieldOutput, E as DBFieldMetadata, F as AuthConfig, Ft as FieldValidateInput, Ht as TailorUser, It as Validators, Jt as output, M as TailorDBServiceInput, Mt as FieldOutput, O as GqlOperationsConfig, Pt as TailorToTs, Wt as InferFieldsOutput, Y as TailorField, c as PluginConfigs, ht as BuiltinIdP, i as TailorDBType$1, j as SerialConfig, jt as FieldOptions, k as IndexDef, kt as EnumValue, qt as Prettify, r as TailorDBField$1, t as TailorAnyDBField$1 } from "./tailor-db-field-CY1D1PtT.mjs";
|
|
3
3
|
import { NonEmptyObject } from "type-fest";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
|
|
@@ -1207,4 +1207,4 @@ type ConcurrencyPolicy = {
|
|
|
1207
1207
|
};
|
|
1208
1208
|
//#endregion
|
|
1209
1209
|
export { PermissionCondition as A, IdPInput as C, TailorDBInstance as D, TailorDBField as E, AllowedValues as F, AllowedValuesOutput as I, TailorTypePermission as M, unsafeAllowAllGqlPermission as N, TailorDBType as O, unsafeAllowAllTypePermission as P, IdPGqlOperationsInput as S, TailorAnyDBType as T, IdPExternalConfig as _, ExecutorServiceInput as a, IdPEmailConfig as b, ResolverServiceInput as c, StaticWebsiteConfig as d, StaticWebsiteDefinitionBrand as f, IdPConfig as g, SecretsDefinitionBrand as h, ExecutorServiceConfig as i, TailorTypeGqlPermission as j, db as k, WorkflowServiceConfig as l, SecretsConfig as m, RetryPolicy as n, ResolverExternalConfig as o, StaticWebsiteInput as p, AppConfig as r, ResolverServiceConfig as s, ConcurrencyPolicy as t, WorkflowServiceInput as u, IdPUserField as v, TailorAnyDBField as w, IdPGqlOperations as x, IdpDefinitionBrand as y };
|
|
1210
|
-
//# sourceMappingURL=workflow.generated
|
|
1210
|
+
//# sourceMappingURL=workflow.generated--YammZcl.d.mts.map
|
package/docs/cli/tailordb.md
CHANGED
|
@@ -93,6 +93,36 @@ tailor-sdk tailordb truncate [options] [types]
|
|
|
93
93
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
94
94
|
|
|
95
95
|
<!-- politty:command:tailordb truncate:global-options-link:end -->
|
|
96
|
+
|
|
97
|
+
**Usage Examples:**
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Truncate all tables in all namespaces (requires confirmation)
|
|
101
|
+
tailor-sdk tailordb truncate --all
|
|
102
|
+
|
|
103
|
+
# Truncate all tables in all namespaces (skip confirmation)
|
|
104
|
+
tailor-sdk tailordb truncate --all --yes
|
|
105
|
+
|
|
106
|
+
# Truncate all tables in a specific namespace
|
|
107
|
+
tailor-sdk tailordb truncate --namespace myNamespace
|
|
108
|
+
|
|
109
|
+
# Truncate specific types (namespace is auto-detected)
|
|
110
|
+
tailor-sdk tailordb truncate User Post Comment
|
|
111
|
+
|
|
112
|
+
# Truncate specific types with confirmation skipped
|
|
113
|
+
tailor-sdk tailordb truncate User Post --yes
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Notes:**
|
|
117
|
+
|
|
118
|
+
- You must specify exactly one of: `--all`, `--namespace`, or type names
|
|
119
|
+
- When truncating specific types, the namespace is automatically detected from your config
|
|
120
|
+
- Confirmation prompts vary based on the operation:
|
|
121
|
+
- `--all`: requires typing `truncate all`
|
|
122
|
+
- `--namespace`: requires typing `truncate <namespace-name>`
|
|
123
|
+
- Specific types: requires typing `yes`
|
|
124
|
+
- Use `--yes` flag to skip confirmation prompts (useful for scripts and CI/CD)
|
|
125
|
+
|
|
96
126
|
<!-- politty:command:tailordb migration:heading:start -->
|
|
97
127
|
|
|
98
128
|
### tailordb migration
|
|
@@ -105,7 +135,7 @@ Manage TailorDB schema migrations.
|
|
|
105
135
|
|
|
106
136
|
<!-- politty:command:tailordb migration:description:end -->
|
|
107
137
|
|
|
108
|
-
Note: Migration scripts are automatically executed during `tailor-sdk apply`. See [Automatic Migration Execution](#automatic-migration-execution) for details.
|
|
138
|
+
Note: Migration scripts are automatically executed during `tailor-sdk apply`. See [Automatic Migration Execution](../services/tailordb-migration.md#automatic-migration-execution) for details.
|
|
109
139
|
|
|
110
140
|
<!-- politty:command:tailordb migration:usage:start -->
|
|
111
141
|
|
|
@@ -265,6 +295,9 @@ tailor-sdk tailordb migration status [options]
|
|
|
265
295
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
266
296
|
|
|
267
297
|
<!-- politty:command:tailordb migration status:global-options-link:end -->
|
|
298
|
+
|
|
299
|
+
**See also:** For migration concepts, configuration, workflow, and troubleshooting, see the [TailorDB Migrations guide](../services/tailordb-migration.md).
|
|
300
|
+
|
|
268
301
|
<!-- politty:command:tailordb erd:heading:start -->
|
|
269
302
|
|
|
270
303
|
### tailordb erd
|
|
@@ -428,420 +461,6 @@ See [Global Options](../cli-reference.md#global-options) for options available t
|
|
|
428
461
|
|
|
429
462
|
**Usage Examples:**
|
|
430
463
|
|
|
431
|
-
```bash
|
|
432
|
-
# Truncate all tables in all namespaces (requires confirmation)
|
|
433
|
-
tailor-sdk tailordb truncate --all
|
|
434
|
-
|
|
435
|
-
# Truncate all tables in all namespaces (skip confirmation)
|
|
436
|
-
tailor-sdk tailordb truncate --all --yes
|
|
437
|
-
|
|
438
|
-
# Truncate all tables in a specific namespace
|
|
439
|
-
tailor-sdk tailordb truncate --namespace myNamespace
|
|
440
|
-
|
|
441
|
-
# Truncate specific types (namespace is auto-detected)
|
|
442
|
-
tailor-sdk tailordb truncate User Post Comment
|
|
443
|
-
|
|
444
|
-
# Truncate specific types with confirmation skipped
|
|
445
|
-
tailor-sdk tailordb truncate User Post --yes
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
**Notes:**
|
|
449
|
-
|
|
450
|
-
- You must specify exactly one of: `--all`, `--namespace`, or type names
|
|
451
|
-
- When truncating specific types, the namespace is automatically detected from your config
|
|
452
|
-
- Confirmation prompts vary based on the operation:
|
|
453
|
-
- `--all`: requires typing `truncate all`
|
|
454
|
-
- `--namespace`: requires typing `truncate <namespace-name>`
|
|
455
|
-
- Specific types: requires typing `yes`
|
|
456
|
-
- Use `--yes` flag to skip confirmation prompts (useful for scripts and CI/CD)
|
|
457
|
-
|
|
458
|
-
### Overview
|
|
459
|
-
|
|
460
|
-
The migration system detects field-level schema differences between your local type definitions and the previous snapshot, then generates migration files to safely apply those changes with data transformations.
|
|
461
|
-
|
|
462
|
-
**Key Features:**
|
|
463
|
-
|
|
464
|
-
- **Local snapshot-based diff detection** between current types and previous migration snapshot
|
|
465
|
-
- **Transaction-wrapped data migrations** for atomicity - all changes commit or rollback together
|
|
466
|
-
- **Automatic execution during apply** - pending migrations run as part of `tailor-sdk apply`
|
|
467
|
-
- **TypeScript migration scripts** - type-safe data transformations using Kysely
|
|
468
|
-
|
|
469
|
-
**Usage Examples:**
|
|
470
|
-
|
|
471
|
-
```bash
|
|
472
|
-
# Generate migration for all schema changes
|
|
473
|
-
tailor-sdk tailordb migration generate
|
|
474
|
-
|
|
475
|
-
# Generate with a description
|
|
476
|
-
tailor-sdk tailordb migration generate --name "add email field to user"
|
|
477
|
-
|
|
478
|
-
# Generate without confirmation prompts
|
|
479
|
-
tailor-sdk tailordb migration generate --yes
|
|
480
|
-
|
|
481
|
-
# Delete existing migrations and start fresh (with confirmation)
|
|
482
|
-
tailor-sdk tailordb migration generate --init
|
|
483
|
-
|
|
484
|
-
# Delete existing migrations and start fresh (skip confirmation)
|
|
485
|
-
tailor-sdk tailordb migration generate --init --yes
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
**Generated Files:**
|
|
489
|
-
|
|
490
|
-
Each migration creates a directory in the migrations folder with a 4-digit sequential number:
|
|
491
|
-
|
|
492
|
-
| File | Description |
|
|
493
|
-
| ------------------ | -------------------------------------------------- |
|
|
494
|
-
| `0000/schema.json` | Initial schema snapshot (first migration only) |
|
|
495
|
-
| `XXXX/diff.json` | Schema diff from previous snapshot |
|
|
496
|
-
| `XXXX/migrate.ts` | Data migration script (only when breaking changes) |
|
|
497
|
-
| `XXXX/db.ts` | Generated Kysely types for the migration script |
|
|
498
|
-
|
|
499
|
-
**Migration Script Structure:**
|
|
500
|
-
|
|
501
|
-
```typescript
|
|
502
|
-
import type { Transaction } from "./db";
|
|
503
|
-
|
|
504
|
-
export async function main(trx: Transaction): Promise<void> {
|
|
505
|
-
// Your data migration logic here
|
|
506
|
-
// All operations use the transaction object (trx)
|
|
507
|
-
await trx.updateTable("User").set({ newField: "default value" }).execute();
|
|
508
|
-
}
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
The `db.ts` file contains Kysely Transaction types that reflect the schema state **before** the migration runs. This ensures type-safe data transformations based on the actual database structure at that point in time.
|
|
512
|
-
|
|
513
|
-
The `main` function receives a Kysely transaction object. All database operations should use this `trx` object to ensure atomicity - if any operation fails, all changes are rolled back.
|
|
514
|
-
|
|
515
|
-
**Editor Integration:**
|
|
516
|
-
|
|
517
|
-
If `VISUAL` or `EDITOR` is set, the generated script file will automatically open in your preferred editor:
|
|
518
|
-
|
|
519
|
-
```bash
|
|
520
|
-
export EDITOR=vim
|
|
521
|
-
tailor-sdk tailordb migration generate
|
|
522
|
-
# → After generation, vim opens XXXX/migrate.ts
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
**Usage Examples:**
|
|
526
|
-
|
|
527
|
-
```bash
|
|
528
|
-
# Set migration checkpoint to 0001 (with confirmation)
|
|
529
|
-
tailor-sdk tailordb migration set 1
|
|
530
|
-
|
|
531
|
-
# Set migration checkpoint without confirmation
|
|
532
|
-
tailor-sdk tailordb migration set 1 --yes
|
|
533
|
-
|
|
534
|
-
# Set for specific namespace
|
|
535
|
-
tailor-sdk tailordb migration set 2 --namespace tailordb
|
|
536
|
-
|
|
537
|
-
# Reset to initial state (all migrations become pending)
|
|
538
|
-
tailor-sdk tailordb migration set 0 --yes
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
**Warning:**
|
|
542
|
-
|
|
543
|
-
Setting the migration checkpoint changes which migrations will be executed on next apply:
|
|
544
|
-
|
|
545
|
-
- **Forward** (e.g., 0001 → 0003): Skips migrations 0002 and 0003
|
|
546
|
-
- **Backward** (e.g., 0003 → 0001): Migrations 0002 and 0003 become pending and will re-execute
|
|
547
|
-
|
|
548
|
-
The command always displays a warning and requires confirmation unless `--yes` is specified.
|
|
549
|
-
|
|
550
|
-
**Usage Examples:**
|
|
551
|
-
|
|
552
|
-
```bash
|
|
553
|
-
# Show status for all namespaces
|
|
554
|
-
tailor-sdk tailordb migration status
|
|
555
|
-
|
|
556
|
-
# Show status for specific namespace
|
|
557
|
-
tailor-sdk tailordb migration status --namespace tailordb
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
**Example Output:**
|
|
561
|
-
|
|
562
|
-
```
|
|
563
|
-
Namespace: tailordb
|
|
564
|
-
Current migration: 0001
|
|
565
|
-
Pending migrations:
|
|
566
|
-
- 0002: Add email field to user
|
|
567
|
-
- 0003: Remove deprecated status field
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
## Configuration
|
|
571
|
-
|
|
572
|
-
Configure migrations in `tailor.config.ts`:
|
|
573
|
-
|
|
574
|
-
```typescript
|
|
575
|
-
export default defineConfig({
|
|
576
|
-
name: "my-app",
|
|
577
|
-
db: {
|
|
578
|
-
tailordb: {
|
|
579
|
-
files: ["./tailordb/*.ts"],
|
|
580
|
-
migration: {
|
|
581
|
-
directory: "./migrations",
|
|
582
|
-
// Optional: specify machine user for migration script execution
|
|
583
|
-
// If not specified, the first machine user from auth.machineUsers is used
|
|
584
|
-
machineUser: "admin-machine-user",
|
|
585
|
-
},
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
});
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
### Configuration Options
|
|
592
|
-
|
|
593
|
-
| Option | Type | Description |
|
|
594
|
-
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
595
|
-
| `files` | string[] | Glob patterns for TailorDB type definition files |
|
|
596
|
-
| `ignores` | string[] | Glob patterns to ignore |
|
|
597
|
-
| `migration.directory` | string | Directory path for migration files |
|
|
598
|
-
| `migration.machineUser` | string | Machine user name for migration script execution (optional, defaults to first machine user from auth.machineUsers) |
|
|
599
|
-
|
|
600
|
-
### Machine User Selection
|
|
601
|
-
|
|
602
|
-
When executing migration scripts, the system selects a machine user in the following priority:
|
|
603
|
-
|
|
604
|
-
1. **Explicit configuration**: `migration.machineUser` in db config
|
|
605
|
-
2. **Auto-selection**: First machine user from `auth.machineUsers`
|
|
606
|
-
|
|
607
|
-
The machine user being used is logged during migration execution.
|
|
608
|
-
|
|
609
|
-
## Migration Directory Structure
|
|
610
|
-
|
|
611
|
-
Migrations use a directory-based structure with 4-digit sequential numbering:
|
|
612
|
-
|
|
613
|
-
```
|
|
614
|
-
migrations/
|
|
615
|
-
├── 0000/ # Initial schema (number 0)
|
|
616
|
-
│ └── schema.json # Full schema snapshot
|
|
617
|
-
├── 0001/ # First change
|
|
618
|
-
│ ├── diff.json # Schema diff
|
|
619
|
-
│ ├── migrate.ts # Migration script (if breaking changes)
|
|
620
|
-
│ └── db.ts # Kysely types (if breaking changes)
|
|
621
|
-
├── 0002/ # Second change
|
|
622
|
-
│ └── diff.json
|
|
623
|
-
└── ...
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
- `0000` - Initial schema snapshot (always starts at 0)
|
|
627
|
-
- `0001` - First schema change
|
|
628
|
-
- `0002` - Second schema change, etc.
|
|
629
|
-
|
|
630
|
-
## Supported Schema Changes
|
|
631
|
-
|
|
632
|
-
| Change Type | Breaking? | Migration Script | Notes |
|
|
633
|
-
| ------------------------------- | --------- | ---------------- | --------------------------------------------- |
|
|
634
|
-
| Add optional field | No | No | Schema change only |
|
|
635
|
-
| Add required field | Yes | Yes | Script populates default values |
|
|
636
|
-
| Remove field | No | No | Schema change only - data is preserved |
|
|
637
|
-
| Change optional→required | Yes | Yes | Script sets defaults for null values |
|
|
638
|
-
| Change required→optional | No | No | Schema change only |
|
|
639
|
-
| Add index | No | No | Schema change only |
|
|
640
|
-
| Remove index | No | No | Schema change only |
|
|
641
|
-
| Add unique constraint | Yes | Yes | Script must resolve duplicate values |
|
|
642
|
-
| Remove unique constraint | No | No | Schema change only |
|
|
643
|
-
| Add enum value | No | No | Schema change only |
|
|
644
|
-
| Remove enum value | Yes | Yes | Script migrates records with removed values |
|
|
645
|
-
| Add type | No | No | Schema change only |
|
|
646
|
-
| Remove type | No | No | Schema change only - data is preserved |
|
|
647
|
-
| Change field type | - | - | **Not supported** - requires 3-step migration |
|
|
648
|
-
| Change array to single value | - | - | **Not supported** - requires 3-step migration |
|
|
649
|
-
| Change single value to array | - | - | **Not supported** - requires 3-step migration |
|
|
650
|
-
| Change foreign key relationship | Yes | Yes | Script updates existing references |
|
|
651
|
-
|
|
652
|
-
### Unsupported Schema Changes
|
|
653
|
-
|
|
654
|
-
The following changes require a 3-step migration process:
|
|
655
|
-
|
|
656
|
-
#### Field Type Change
|
|
657
|
-
|
|
658
|
-
Field type changes (e.g., `string` → `integer`) are not directly supported. Use this migration strategy:
|
|
659
|
-
|
|
660
|
-
1. **Migration 1**: Add a new field with the desired type (e.g., `fieldName_new`) and migrate data
|
|
661
|
-
2. **Migration 2**: Remove the old field
|
|
662
|
-
3. **Migration 3**: Add the field with the original name and new type, migrate data from temporary field, then remove temporary field
|
|
663
|
-
|
|
664
|
-
#### Array Property Change
|
|
665
|
-
|
|
666
|
-
Changing between single value and array (e.g., `array: false` → `array: true`) is not directly supported. Use the same 3-step migration strategy as field type changes.
|
|
667
|
-
|
|
668
|
-
## Example Workflow
|
|
669
|
-
|
|
670
|
-
1. **Modify your type definition:**
|
|
671
|
-
|
|
672
|
-
```typescript
|
|
673
|
-
// tailordb/user.ts
|
|
674
|
-
export const user = db.type("User", {
|
|
675
|
-
name: db.string(),
|
|
676
|
-
email: db.string(), // ← New required field
|
|
677
|
-
...db.fields.timestamps(),
|
|
678
|
-
});
|
|
679
|
-
```
|
|
680
|
-
|
|
681
|
-
2. **Generate migration:**
|
|
682
|
-
|
|
683
|
-
```bash
|
|
684
|
-
tailor-sdk tailordb migration generate
|
|
685
|
-
# Output: Generated migration 0001
|
|
686
|
-
# Diff file: ./migrations/0001/diff.json
|
|
687
|
-
# Migration script: ./migrations/0001/migrate.ts
|
|
688
|
-
# DB types: ./migrations/0001/db.ts
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
3. **Edit the migration script** (`0001/migrate.ts`):
|
|
692
|
-
|
|
693
|
-
```typescript
|
|
694
|
-
import type { Transaction } from "./db";
|
|
695
|
-
|
|
696
|
-
export async function main(trx: Transaction): Promise<void> {
|
|
697
|
-
await trx
|
|
698
|
-
.updateTable("User")
|
|
699
|
-
.set({ email: "default@example.com" })
|
|
700
|
-
.where("email", "is", null)
|
|
701
|
-
.execute();
|
|
702
|
-
}
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
4. **Apply migration:**
|
|
706
|
-
```bash
|
|
707
|
-
tailor-sdk apply
|
|
708
|
-
# Migrations are automatically executed during apply
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
## Automatic Migration Execution
|
|
712
|
-
|
|
713
|
-
When running `tailor-sdk apply`, pending migration scripts are automatically executed as part of the deployment process.
|
|
714
|
-
|
|
715
|
-
### How It Works
|
|
716
|
-
|
|
717
|
-
1. **Pending Migration Detection**: Identifies migration scripts that haven't been executed yet
|
|
718
|
-
2. **Two-Stage Type Update**: For breaking changes (required fields, type changes):
|
|
719
|
-
- **Pre-Migration**: New fields are added as `optional` first
|
|
720
|
-
- **Script Execution**: Migration scripts run to populate data
|
|
721
|
-
- **Post-Migration**: Fields are changed to `required`, deletions are applied
|
|
722
|
-
|
|
723
|
-
### Execution Flow
|
|
724
|
-
|
|
725
|
-
```
|
|
726
|
-
tailor-sdk apply
|
|
727
|
-
│
|
|
728
|
-
├── Detect Pending Migrations
|
|
729
|
-
│
|
|
730
|
-
├── [If pending migrations exist]
|
|
731
|
-
│ ├── Pre-Migration: Add fields as optional
|
|
732
|
-
│ ├── Execute Migration Scripts (TestExecScript API)
|
|
733
|
-
│ └── Post-Migration: Apply required, deletions
|
|
734
|
-
│
|
|
735
|
-
└── Continue with normal apply flow
|
|
736
|
-
```
|
|
737
|
-
|
|
738
|
-
### Requirements for Automatic Migration
|
|
739
|
-
|
|
740
|
-
1. **Migrations configured**: `migrations` path set in db config
|
|
741
|
-
2. **Auth configured**: Auth service with machine users
|
|
742
|
-
3. **Kysely generator**: `@tailor-platform/kysely-type` generator configured
|
|
743
|
-
|
|
744
|
-
### Schema Verification
|
|
745
|
-
|
|
746
|
-
By default, `tailor-sdk apply` performs two schema verifications:
|
|
747
|
-
|
|
748
|
-
1. **Local schema check**: Ensures local type definitions match the migration snapshot
|
|
749
|
-
2. **Remote schema check**: Ensures remote schema matches the expected state based on migration history
|
|
750
|
-
|
|
751
|
-
If remote schema drift is detected, you'll see an error like:
|
|
752
|
-
|
|
753
|
-
```
|
|
754
|
-
✖ Remote schema drift detected:
|
|
755
|
-
Namespace: tailordb
|
|
756
|
-
Remote migration: 0007
|
|
757
|
-
Differences:
|
|
758
|
-
Type 'User':
|
|
759
|
-
- Field 'email': required: remote=false, expected=true
|
|
760
|
-
|
|
761
|
-
ℹ This may indicate:
|
|
762
|
-
- Another developer applied different migrations
|
|
763
|
-
- Manual schema changes were made directly
|
|
764
|
-
- Migration history is out of sync
|
|
765
|
-
|
|
766
|
-
ℹ Use '--no-schema-check' to skip this check (not recommended).
|
|
767
|
-
```
|
|
768
|
-
|
|
769
|
-
### Skipping Schema Check
|
|
770
|
-
|
|
771
|
-
To skip both local and remote schema verification (not recommended for production):
|
|
772
|
-
|
|
773
|
-
```bash
|
|
774
|
-
tailor-sdk apply --no-schema-check
|
|
775
|
-
```
|
|
776
|
-
|
|
777
|
-
**Warning:** Skipping schema checks may result in applying migrations to an inconsistent state.
|
|
778
|
-
|
|
779
|
-
### Example Output
|
|
780
|
-
|
|
781
|
-
```
|
|
782
|
-
ℹ Found 2 pending migration(s) to execute.
|
|
783
|
-
ℹ Executing 2 pending migration(s)...
|
|
784
|
-
ℹ Using machine user: admin-machine-user
|
|
785
|
-
|
|
786
|
-
✔ Migration tailordb/0002 completed successfully
|
|
787
|
-
✔ Migration tailordb/0003 completed successfully
|
|
788
|
-
|
|
789
|
-
✔ All migrations completed successfully.
|
|
790
|
-
✔ Successfully applied changes.
|
|
791
|
-
```
|
|
792
|
-
|
|
793
|
-
## Troubleshooting
|
|
794
|
-
|
|
795
|
-
### Remote schema drift detected
|
|
796
|
-
|
|
797
|
-
**Cause:** The remote schema doesn't match the expected state based on migration history. This can happen when:
|
|
798
|
-
|
|
799
|
-
- Another developer applied different migrations
|
|
800
|
-
- Schema was changed manually outside of migrations
|
|
801
|
-
- Migration history is out of sync
|
|
802
|
-
|
|
803
|
-
**Solution:**
|
|
804
|
-
|
|
805
|
-
1. **Check migration status**: Run `tailor-sdk tailordb migration status` to see current state
|
|
806
|
-
2. **Sync with team**: Ensure all team members have the same migration files
|
|
807
|
-
3. **Reset if needed**: Use `tailor-sdk tailordb migration set <number>` to reset migration checkpoint
|
|
808
|
-
4. **Force apply** (use with caution): Use `--no-schema-check` to skip verification
|
|
809
|
-
|
|
810
|
-
### "Machine user not found"
|
|
811
|
-
|
|
812
|
-
**Cause:** Specified machine user doesn't exist in auth configuration.
|
|
813
|
-
|
|
814
|
-
**Solution:**
|
|
815
|
-
|
|
816
|
-
1. Check available users: The error message lists available machine users
|
|
817
|
-
2. Add machine user to your auth config:
|
|
818
|
-
```typescript
|
|
819
|
-
machineUsers: {
|
|
820
|
-
"your-user-name": {
|
|
821
|
-
attributes: { role: "ADMIN" },
|
|
822
|
-
},
|
|
823
|
-
}
|
|
824
|
-
```
|
|
825
|
-
3. Run `tailor-sdk apply` to deploy the auth config
|
|
826
|
-
4. Retry migration
|
|
827
|
-
|
|
828
|
-
### Migration script execution fails
|
|
829
|
-
|
|
830
|
-
**Cause:** Runtime error in your data migration logic.
|
|
831
|
-
|
|
832
|
-
**Solution:**
|
|
833
|
-
|
|
834
|
-
1. Check the error message for the failing query/operation
|
|
835
|
-
2. Test your script logic locally if possible
|
|
836
|
-
3. Fix the script
|
|
837
|
-
4. Apply again: `tailor-sdk apply`
|
|
838
|
-
|
|
839
|
-
**Notes:**
|
|
840
|
-
|
|
841
|
-
- This command is a beta feature and may introduce breaking changes in future releases
|
|
842
|
-
|
|
843
|
-
**Usage Examples:**
|
|
844
|
-
|
|
845
464
|
```bash
|
|
846
465
|
# Deploy ERD for all namespaces with erdSite configured
|
|
847
466
|
tailor-sdk tailordb erd deploy
|
|
@@ -855,6 +474,7 @@ tailor-sdk tailordb erd deploy --json
|
|
|
855
474
|
|
|
856
475
|
**Notes:**
|
|
857
476
|
|
|
477
|
+
- This command is a beta feature and may introduce breaking changes in future releases
|
|
858
478
|
- Requires `erdSite` to be configured in `tailor.config.ts` for each namespace you want to deploy
|
|
859
479
|
- Example config:
|
|
860
480
|
```typescript
|
|
@@ -130,7 +130,15 @@ Fire when IdP users are created, updated, or deleted:
|
|
|
130
130
|
idpUserCreatedTrigger();
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
When the project defines multiple IdPs, pass `idp` to target a specific one. The name is type-narrowed via the generated `IdpName` type:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
idpUserCreatedTrigger({ idp: "my-idp" });
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Omitting `idp` is allowed only when the project has exactly one IdP; otherwise `apply` fails with an error listing the configured IdPs.
|
|
140
|
+
|
|
141
|
+
These triggers require the IdP to publish user lifecycle events. The SDK enables `publishUserEvents` automatically during `apply` on each IdP that is targeted by an `idpUser` trigger; set the value explicitly on `defineIdp()` to override. See [IdP service - publishUserEvents](./idp.md#publishuserevents).
|
|
134
142
|
|
|
135
143
|
### Auth Access Token Triggers
|
|
136
144
|
|
|
@@ -180,6 +188,12 @@ export default createExecutor({
|
|
|
180
188
|
idpUserTrigger({ events: ["created", "deleted"] });
|
|
181
189
|
```
|
|
182
190
|
|
|
191
|
+
In multi-IdP projects, add `idp` to target a specific IdP:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
idpUserTrigger({ events: ["created", "deleted"], idp: "my-idp" });
|
|
195
|
+
```
|
|
196
|
+
|
|
183
197
|
#### `authAccessTokenTrigger()`
|
|
184
198
|
|
|
185
199
|
```typescript
|
package/docs/services/idp.md
CHANGED
|
@@ -175,10 +175,10 @@ defineIdp("my-idp", {
|
|
|
175
175
|
});
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
**Auto-configuration:** When `publishUserEvents` is omitted, the SDK enables it automatically during `apply`
|
|
178
|
+
**Auto-configuration:** When `publishUserEvents` is omitted, the SDK enables it automatically during `apply` for each IdP that is targeted by an executor's `idpUser` trigger. Targeting is per-IdP: an executor specifies which IdP it subscribes to via the trigger's `idp` option (required in multi-IdP projects). Set the value explicitly to override:
|
|
179
179
|
|
|
180
180
|
- `publishUserEvents: true`: always publish events.
|
|
181
|
-
- `publishUserEvents: false`: never publish events.
|
|
181
|
+
- `publishUserEvents: false`: never publish events. `apply` rejects this with an error if any executor's `idpUser` trigger targets this IdP — either remove `publishUserEvents: false` or remove the matching trigger.
|
|
182
182
|
|
|
183
183
|
## Using idp.provider()
|
|
184
184
|
|