import { SnapshotFieldConfig, SnapshotGqlPermission, SnapshotIndexConfig, SnapshotRecordPermission, SnapshotRelationship, TailorDBSnapshotType } from "./snapshot-types.mjs"; //#region src/cli/commands/tailordb/migrate/diff-calculator.d.ts /** * Properties shared by all diff change variants */ interface DiffChangeBase { tableName: string; reason?: string; } /** * Table-level settings patch carried by legacy `type_modified` changes. * Current SDK versions no longer produce this kind, but persisted * diff.json files written by older versions may still contain it. */ export interface TypeSettingsPatch { indexes?: Record; files?: Record; } /** Table-level settings and metadata state used by current diffs. */ export interface SnapshotTypeSettingsState { description?: string; pluralForm: string; settings?: TailorDBSnapshotType["settings"]; } /** * Permission state carried by `permission_modified` changes. */ export interface SnapshotPermissionState { recordPermission?: SnapshotRecordPermission; gqlPermission?: SnapshotGqlPermission; } /** A new table was added to the schema. */ export interface TableAddedChange extends DiffChangeBase { kind: "table_added"; after: TailorDBSnapshotType; } /** An existing table was removed from the schema. */ export interface TableRemovedChange extends DiffChangeBase { kind: "table_removed"; before: TailorDBSnapshotType; } /** * A table was renamed. Recorded when the user confirms that a removed + added * table pair is a rename (interactively or via `--rename`). * `tableName` is the new name; `previousTableName` is the old name. */ export interface TableRenamedChange extends DiffChangeBase { kind: "table_renamed"; previousTableName: string; before: TailorDBSnapshotType; after: TailorDBSnapshotType; } /** * Legacy table-level settings change. Kept for backward compatibility with * diff.json files written by older SDK versions; `before`/`after` may be * absent in those files, hence optional. */ export interface TableModifiedChange extends DiffChangeBase { kind: "table_modified"; before?: TypeSettingsPatch; after?: TypeSettingsPatch; } /** Table-level settings or metadata changed. */ export interface TableSettingsModifiedChange extends DiffChangeBase { kind: "table_settings_modified"; before: SnapshotTypeSettingsState; after: SnapshotTypeSettingsState; } /** A field was added to a table. */ export interface FieldAddedChange extends DiffChangeBase { kind: "field_added"; fieldName: string; after: SnapshotFieldConfig; } /** A field was removed from a table. */ export interface FieldRemovedChange extends DiffChangeBase { kind: "field_removed"; fieldName: string; before: SnapshotFieldConfig; } /** * A member inside a nested field was renamed. `previousPath` and `path` are * relative to the top-level field and share the same parent. */ export interface NestedMemberRename { previousPath: string[]; path: string[]; } /** * A field configuration was modified. `memberRenames` records members inside a * nested field that the user confirmed as renames (interactively or via * `--rename Table.field.old:new`); their values must be copied by the * migration script. */ export interface FieldModifiedChange extends DiffChangeBase { kind: "field_modified"; fieldName: string; before: SnapshotFieldConfig; after: SnapshotFieldConfig; memberRenames?: NestedMemberRename[]; } /** * A field was renamed within a table. Recorded when the user confirms that a * removed + added field pair is a rename (interactively or via `--rename`). * `fieldName` is the new name; `previousFieldName` is the old name. */ export interface FieldRenamedChange extends DiffChangeBase { kind: "field_renamed"; fieldName: string; previousFieldName: string; before: SnapshotFieldConfig; after: SnapshotFieldConfig; } /** A field type changed and must remain on the previous type until Post-phase. */ export interface FieldTypeModifiedChange extends DiffChangeBase { kind: "field_type_modified"; fieldName: string; before: SnapshotFieldConfig; after: SnapshotFieldConfig; } /** An index was added to a table. */ export interface IndexAddedChange extends DiffChangeBase { kind: "index_added"; indexName: string; after: SnapshotIndexConfig; } /** An index was removed from a table. */ export interface IndexRemovedChange extends DiffChangeBase { kind: "index_removed"; indexName: string; before: SnapshotIndexConfig; } /** An index configuration was modified. */ export interface IndexModifiedChange extends DiffChangeBase { kind: "index_modified"; indexName: string; before: SnapshotIndexConfig; after: SnapshotIndexConfig; } /** A file field was added to a table. `before`/`after` hold the description. */ export interface FileAddedChange extends DiffChangeBase { kind: "file_added"; fieldName: string; after: string; } /** A file field was removed from a table. */ export interface FileRemovedChange extends DiffChangeBase { kind: "file_removed"; fieldName: string; before: string; } /** A file field description was modified. */ export interface FileModifiedChange extends DiffChangeBase { kind: "file_modified"; fieldName: string; before: string; after: string; } /** * A relationship was added to a table. `relationshipType` is optional for * backward compatibility: diff.json files written by older SDK versions * predate the field. */ export interface RelationshipAddedChange extends DiffChangeBase { kind: "relationship_added"; relationshipName: string; relationshipType?: "forward" | "backward"; after: SnapshotRelationship; } /** A relationship was removed from a table. */ export interface RelationshipRemovedChange extends DiffChangeBase { kind: "relationship_removed"; relationshipName: string; relationshipType?: "forward" | "backward"; before: SnapshotRelationship; } /** A relationship configuration was modified. */ export interface RelationshipModifiedChange extends DiffChangeBase { kind: "relationship_modified"; relationshipName: string; relationshipType?: "forward" | "backward"; before: SnapshotRelationship; after: SnapshotRelationship; } /** * Table-level permissions were modified. `before`/`after` are optional for * robustness against hand-edited or legacy diff.json files; consumers guard * on their presence. */ export interface PermissionModifiedChange extends DiffChangeBase { kind: "permission_modified"; before?: SnapshotPermissionState; after?: SnapshotPermissionState; } /** Table-level hook/validate script state for diff tracking. */ export interface TypeScriptsState { typeHookExpr?: { create?: string; update?: string; }; typeValidateExpr?: string; } /** Table-level hook/validate scripts changed. */ export interface TableScriptsModifiedChange extends DiffChangeBase { kind: "table_scripts_modified"; before: TypeScriptsState; after: TypeScriptsState; } /** * Single change in migration diff, discriminated by `kind` so that * `before`/`after` are typed per change kind. */ export type DiffChange = TableAddedChange | TableRemovedChange | TableRenamedChange | TableModifiedChange | TableSettingsModifiedChange | FieldAddedChange | FieldRemovedChange | FieldModifiedChange | FieldRenamedChange | FieldTypeModifiedChange | IndexAddedChange | IndexRemovedChange | IndexModifiedChange | FileAddedChange | FileRemovedChange | FileModifiedChange | RelationshipAddedChange | RelationshipRemovedChange | RelationshipModifiedChange | PermissionModifiedChange | TableScriptsModifiedChange; /** * Migration diff - changes between two schema versions * Stored as XXXX/diff.json (e.g., 0001/diff.json) */ export interface MigrationDiff { /** Format version for future compatibility */ version: number; namespace: string; createdAt: string; description?: string; changes: DiffChange[]; /** Whether there are breaking changes (data loss or constraint violations possible) */ hasBreakingChanges: boolean; /** List of breaking changes */ breakingChanges: BreakingChangeInfo[]; /** Whether there are non-breaking changes that may cause data loss (e.g. field/table removal) */ hasWarnings: boolean; /** List of non-breaking warnings */ warnings: WarningChangeInfo[]; /** Whether a migration script is required to handle data migration */ requiresMigrationScript: boolean; /** Explicit acknowledgment that this migration needs no script despite breaking changes or data-loss warnings */ scriptSkipped?: ScriptSkippedInfo; } /** * Acknowledgment that a migration requiring or recommending a script intentionally has none. * Recorded by `tailordb migration script --no-script --reason "..."`. */ export interface ScriptSkippedInfo { reason: string; acknowledgedAt: string; } /** * Breaking change information in migration diff */ export interface BreakingChangeInfo { tableName: string; fieldName?: string; reason: string; /** If true, this change is not supported and migration generation will fail */ unsupported?: boolean; /** If true, show 3-step migration instructions for this unsupported change */ showThreeStepHint?: boolean; } /** * Warning change information in migration diff. * * Warnings are non-breaking changes that may still cause data loss * (e.g. removing a field or table). Unlike breaking changes, a migration * script is not required, but writing one is recommended if you need to * preserve or transform data before the change applies. */ export interface WarningChangeInfo { tableName: string; /** Field name, or the dotted path of a member inside a nested field (e.g. `address.zip`). */ fieldName?: string; reason: string; } /** * Check if a migration diff has any changes * @param {MigrationDiff} diff - Migration diff to check * @returns {boolean} True if diff has changes */ export declare function hasChanges(diff: MigrationDiff): boolean; /** * Format a migration diff for display * @param {MigrationDiff} diff - Migration diff to format * @returns {string} Formatted diff string */ export declare function formatMigrationDiff(diff: MigrationDiff): string; /** * Format a summary of the migration diff * @param {MigrationDiff} diff - Migration diff to summarize * @returns {string} Formatted summary string */ export declare function formatDiffSummary(diff: MigrationDiff): string; //#endregion