appwrite-utils-cli 1.11.0 → 1.12.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/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -1
- package/dist/adapters/index.js +10 -0
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +210 -0
- package/dist/cli/commands/databaseCommands.d.ts +14 -0
- package/dist/cli/commands/databaseCommands.js +696 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +330 -0
- package/dist/cli/commands/importFileCommands.d.ts +7 -0
- package/dist/cli/commands/importFileCommands.js +674 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +169 -0
- package/dist/cli/commands/storageCommands.d.ts +5 -0
- package/dist/cli/commands/storageCommands.js +142 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +382 -0
- package/dist/collections/columns.d.ts +13 -0
- package/dist/collections/columns.js +1339 -0
- package/dist/collections/indexes.d.ts +12 -0
- package/dist/collections/indexes.js +215 -0
- package/dist/collections/methods.d.ts +19 -0
- package/dist/collections/methods.js +605 -0
- package/dist/collections/tableOperations.d.ts +87 -0
- package/dist/collections/tableOperations.js +466 -0
- package/dist/collections/transferOperations.d.ts +8 -0
- package/dist/collections/transferOperations.js +411 -0
- package/dist/collections/wipeOperations.d.ts +17 -0
- package/dist/collections/wipeOperations.js +306 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +35 -0
- package/dist/databases/setup.d.ts +5 -0
- package/dist/databases/setup.js +45 -0
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +272 -0
- package/dist/functions/deployments.d.ts +4 -0
- package/dist/functions/deployments.js +146 -0
- package/dist/functions/fnConfigDiscovery.d.ts +3 -0
- package/dist/functions/fnConfigDiscovery.js +108 -0
- package/dist/functions/methods.d.ts +16 -0
- package/dist/functions/methods.js +174 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/interactiveCLI.d.ts +36 -0
- package/dist/interactiveCLI.js +952 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +1125 -0
- package/dist/migrations/afterImportActions.d.ts +17 -0
- package/dist/migrations/afterImportActions.js +305 -0
- package/dist/migrations/appwriteToX.d.ts +211 -0
- package/dist/migrations/appwriteToX.js +493 -0
- package/dist/migrations/comprehensiveTransfer.d.ts +147 -0
- package/dist/migrations/comprehensiveTransfer.js +1315 -0
- package/dist/migrations/dataLoader.d.ts +755 -0
- package/dist/migrations/dataLoader.js +1272 -0
- package/dist/migrations/importController.d.ts +25 -0
- package/dist/migrations/importController.js +283 -0
- package/dist/migrations/importDataActions.d.ts +50 -0
- package/dist/migrations/importDataActions.js +230 -0
- package/dist/migrations/relationships.d.ts +29 -0
- package/dist/migrations/relationships.js +203 -0
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +99 -0
- package/dist/migrations/services/ImportOrchestrator.js +493 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +30 -0
- package/dist/migrations/transfer.js +661 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +131 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +383 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +93 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +341 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +30 -0
- package/dist/migrations/yaml/generateImportSchemas.js +1327 -0
- package/dist/schemas/authUser.d.ts +24 -0
- package/dist/schemas/authUser.js +17 -0
- package/dist/setup.d.ts +2 -0
- package/{src/setup.ts → dist/setup.js} +0 -3
- package/dist/setupCommands.d.ts +58 -0
- package/dist/setupCommands.js +489 -0
- package/dist/setupController.d.ts +9 -0
- package/dist/setupController.js +34 -0
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/migrationHelpers.d.ts +61 -0
- package/dist/shared/migrationHelpers.js +145 -0
- package/{src/shared/operationLogger.ts → dist/shared/operationLogger.d.ts} +1 -11
- package/dist/shared/operationLogger.js +12 -0
- package/dist/shared/operationQueue.d.ts +40 -0
- package/dist/shared/operationQueue.js +310 -0
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +287 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/selectionDialogs.d.ts +220 -0
- package/dist/shared/selectionDialogs.js +588 -0
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +44 -0
- package/dist/storage/methods.js +475 -0
- package/dist/storage/schemas.d.ts +842 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/tables/indexManager.d.ts +65 -0
- package/dist/tables/indexManager.js +294 -0
- package/{src/types.ts → dist/types.d.ts} +1 -6
- package/dist/types.js +3 -0
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +261 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/loadConfigs.d.ts +50 -0
- package/dist/utils/loadConfigs.js +357 -0
- package/dist/utils/setupFiles.d.ts +4 -0
- package/dist/utils/setupFiles.js +1190 -0
- package/dist/utilsController.d.ts +114 -0
- package/dist/utilsController.js +898 -0
- package/package.json +6 -3
- package/CHANGELOG.md +0 -35
- package/CONFIG_TODO.md +0 -1189
- package/SELECTION_DIALOGS.md +0 -146
- package/SERVICE_IMPLEMENTATION_REPORT.md +0 -462
- package/scripts/copy-templates.ts +0 -23
- package/src/backups/operations/bucketBackup.ts +0 -277
- package/src/backups/operations/collectionBackup.ts +0 -310
- package/src/backups/operations/comprehensiveBackup.ts +0 -342
- package/src/backups/schemas/bucketManifest.ts +0 -78
- package/src/backups/schemas/comprehensiveManifest.ts +0 -76
- package/src/backups/tracking/centralizedTracking.ts +0 -352
- package/src/cli/commands/configCommands.ts +0 -265
- package/src/cli/commands/databaseCommands.ts +0 -931
- package/src/cli/commands/functionCommands.ts +0 -419
- package/src/cli/commands/importFileCommands.ts +0 -815
- package/src/cli/commands/schemaCommands.ts +0 -200
- package/src/cli/commands/storageCommands.ts +0 -151
- package/src/cli/commands/transferCommands.ts +0 -454
- package/src/collections/attributes.ts.backup +0 -1555
- package/src/collections/columns.ts +0 -2025
- package/src/collections/indexes.ts +0 -350
- package/src/collections/methods.ts +0 -714
- package/src/collections/tableOperations.ts +0 -542
- package/src/collections/transferOperations.ts +0 -589
- package/src/collections/wipeOperations.ts +0 -449
- package/src/databases/methods.ts +0 -49
- package/src/databases/setup.ts +0 -77
- package/src/examples/yamlTerminologyExample.ts +0 -346
- package/src/functions/deployments.ts +0 -221
- package/src/functions/fnConfigDiscovery.ts +0 -103
- package/src/functions/methods.ts +0 -284
- package/src/init.ts +0 -62
- package/src/interactiveCLI.ts +0 -1201
- package/src/main.ts +0 -1517
- package/src/migrations/afterImportActions.ts +0 -579
- package/src/migrations/appwriteToX.ts +0 -668
- package/src/migrations/comprehensiveTransfer.ts +0 -2285
- package/src/migrations/dataLoader.ts +0 -1729
- package/src/migrations/importController.ts +0 -440
- package/src/migrations/importDataActions.ts +0 -315
- package/src/migrations/relationships.ts +0 -333
- package/src/migrations/services/DataTransformationService.ts +0 -196
- package/src/migrations/services/FileHandlerService.ts +0 -311
- package/src/migrations/services/ImportOrchestrator.ts +0 -675
- package/src/migrations/services/RateLimitManager.ts +0 -363
- package/src/migrations/services/RelationshipResolver.ts +0 -461
- package/src/migrations/services/UserMappingService.ts +0 -345
- package/src/migrations/services/ValidationService.ts +0 -349
- package/src/migrations/transfer.ts +0 -1113
- package/src/migrations/yaml/YamlImportConfigLoader.ts +0 -439
- package/src/migrations/yaml/YamlImportIntegration.ts +0 -446
- package/src/migrations/yaml/generateImportSchemas.ts +0 -1354
- package/src/schemas/authUser.ts +0 -23
- package/src/setupCommands.ts +0 -602
- package/src/setupController.ts +0 -43
- package/src/shared/backupMetadataSchema.ts +0 -93
- package/src/shared/backupTracking.ts +0 -211
- package/src/shared/confirmationDialogs.ts +0 -327
- package/src/shared/migrationHelpers.ts +0 -232
- package/src/shared/operationQueue.ts +0 -376
- package/src/shared/operationsTable.ts +0 -338
- package/src/shared/operationsTableSchema.ts +0 -60
- package/src/shared/progressManager.ts +0 -278
- package/src/shared/relationshipExtractor.ts +0 -214
- package/src/shared/selectionDialogs.ts +0 -802
- package/src/storage/backupCompression.ts +0 -88
- package/src/storage/methods.ts +0 -711
- package/src/storage/schemas.ts +0 -205
- package/src/tables/indexManager.ts +0 -409
- package/src/types/node-appwrite-tablesdb.d.ts +0 -44
- package/src/users/methods.ts +0 -358
- package/src/utils/configMigration.ts +0 -348
- package/src/utils/loadConfigs.ts +0 -457
- package/src/utils/setupFiles.ts +0 -1236
- package/src/utilsController.ts +0 -1263
- package/tests/README.md +0 -497
- package/tests/adapters/AdapterFactory.test.ts +0 -277
- package/tests/integration/syncOperations.test.ts +0 -463
- package/tests/jest.config.js +0 -25
- package/tests/migration/configMigration.test.ts +0 -546
- package/tests/setup.ts +0 -62
- package/tests/testUtils.ts +0 -340
- package/tests/utils/loadConfigs.test.ts +0 -350
- package/tests/validation/configValidation.test.ts +0 -412
- package/tsconfig.json +0 -44
- /package/{src → dist}/functions/templates/count-docs-in-collection/README.md +0 -0
- /package/{src → dist}/functions/templates/count-docs-in-collection/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/count-docs-in-collection/src/request.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/README.md +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/adapters/request.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/adapters/response.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/app.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/context.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -0
- /package/{src → dist}/functions/templates/typescript-node/README.md +0 -0
- /package/{src → dist}/functions/templates/typescript-node/src/context.ts +0 -0
- /package/{src → dist}/functions/templates/typescript-node/src/main.ts +0 -0
- /package/{src → dist}/functions/templates/uv/README.md +0 -0
- /package/{src → dist}/functions/templates/uv/pyproject.toml +0 -0
- /package/{src → dist}/functions/templates/uv/src/__init__.py +0 -0
- /package/{src → dist}/functions/templates/uv/src/context.py +0 -0
- /package/{src → dist}/functions/templates/uv/src/main.py +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Schema for centralized backup tracking table (_appwrite_backups)
|
|
5
|
-
*
|
|
6
|
-
* Tracks all backups created for databases, buckets, and comprehensive backups
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export type BackupType = 'database' | 'bucket' | 'comprehensive';
|
|
10
|
-
export type BackupFormat = 'json' | 'zip';
|
|
11
|
-
export type BackupStatus = 'completed' | 'partial' | 'failed';
|
|
12
|
-
export type RestorationStatus = 'completed' | 'partial' | 'failed' | 'not_restored';
|
|
13
|
-
|
|
14
|
-
export const BACKUP_TYPES = ['database', 'bucket', 'comprehensive'] as const;
|
|
15
|
-
export const BACKUP_FORMATS = ['json', 'zip'] as const;
|
|
16
|
-
export const BACKUP_STATUSES = ['completed', 'partial', 'failed'] as const;
|
|
17
|
-
export const RESTORATION_STATUSES = ['completed', 'partial', 'failed', 'not_restored'] as const;
|
|
18
|
-
|
|
19
|
-
export const BackupTypeSchema = z.enum(['database', 'bucket', 'comprehensive']);
|
|
20
|
-
export const BackupFormatSchema = z.enum(['json', 'zip']);
|
|
21
|
-
export const BackupStatusSchema = z.enum(['completed', 'partial', 'failed']);
|
|
22
|
-
export const RestorationStatusSchema = z.enum(['completed', 'partial', 'failed', 'not_restored']);
|
|
23
|
-
|
|
24
|
-
export interface BackupMetadata {
|
|
25
|
-
$id: string;
|
|
26
|
-
$createdAt: string;
|
|
27
|
-
$updatedAt: string;
|
|
28
|
-
|
|
29
|
-
// Core backup info
|
|
30
|
-
backupType: BackupType; // Type of backup: database, bucket, or comprehensive
|
|
31
|
-
backupId: string; // File ID in storage bucket for the backup file
|
|
32
|
-
manifestFileId?: string; // File ID for the manifest JSON file
|
|
33
|
-
format: BackupFormat; // 'json' or 'zip'
|
|
34
|
-
sizeBytes: number; // Total backup file size
|
|
35
|
-
|
|
36
|
-
// Resource identification (at least one must be present)
|
|
37
|
-
databaseId?: string; // Database ID (for database backups)
|
|
38
|
-
bucketId?: string; // Bucket ID (for bucket backups)
|
|
39
|
-
comprehensiveBackupId?: string; // Parent comprehensive backup ID
|
|
40
|
-
|
|
41
|
-
// Database-specific metrics
|
|
42
|
-
collections?: number; // Number of collections backed up
|
|
43
|
-
documents?: number; // Number of documents backed up
|
|
44
|
-
|
|
45
|
-
// Bucket-specific metrics
|
|
46
|
-
fileCount?: number; // Number of files backed up (for bucket backups)
|
|
47
|
-
|
|
48
|
-
// Status tracking
|
|
49
|
-
status: BackupStatus; // 'completed', 'partial', or 'failed'
|
|
50
|
-
error?: string; // Error message if failed or partial
|
|
51
|
-
|
|
52
|
-
// Restoration tracking
|
|
53
|
-
restoredAt?: string; // ISO timestamp of restoration
|
|
54
|
-
restorationStatus: RestorationStatus; // Restoration status
|
|
55
|
-
restorationError?: string; // Error message if restoration failed
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const BackupMetadataSchema = z.object({
|
|
59
|
-
$id: z.string(),
|
|
60
|
-
$createdAt: z.string(),
|
|
61
|
-
$updatedAt: z.string(),
|
|
62
|
-
|
|
63
|
-
// Core backup info
|
|
64
|
-
backupType: BackupTypeSchema,
|
|
65
|
-
backupId: z.string(),
|
|
66
|
-
manifestFileId: z.string().optional(),
|
|
67
|
-
format: BackupFormatSchema,
|
|
68
|
-
sizeBytes: z.number(),
|
|
69
|
-
|
|
70
|
-
// Resource identification
|
|
71
|
-
databaseId: z.string().optional(),
|
|
72
|
-
bucketId: z.string().optional(),
|
|
73
|
-
comprehensiveBackupId: z.string().optional(),
|
|
74
|
-
|
|
75
|
-
// Database-specific metrics
|
|
76
|
-
collections: z.number().optional(),
|
|
77
|
-
documents: z.number().optional(),
|
|
78
|
-
|
|
79
|
-
// Bucket-specific metrics
|
|
80
|
-
fileCount: z.number().optional(),
|
|
81
|
-
|
|
82
|
-
// Status tracking
|
|
83
|
-
status: BackupStatusSchema,
|
|
84
|
-
error: z.string().optional(),
|
|
85
|
-
|
|
86
|
-
// Restoration tracking
|
|
87
|
-
restoredAt: z.string().optional(),
|
|
88
|
-
restorationStatus: RestorationStatusSchema.default('not_restored'),
|
|
89
|
-
restorationError: z.string().optional()
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export const BACKUP_TABLE_ID = "appwrite_backups";
|
|
93
|
-
export const BACKUP_TABLE_NAME = "Backup Tracking";
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import type { DatabaseAdapter } from "appwrite-utils-helpers";
|
|
2
|
-
import { logger } from 'appwrite-utils-helpers';
|
|
3
|
-
import { tryAwaitWithRetry } from "appwrite-utils-helpers";
|
|
4
|
-
import { Query, ID } from "node-appwrite";
|
|
5
|
-
import {
|
|
6
|
-
BACKUP_TABLE_ID,
|
|
7
|
-
BACKUP_TABLE_NAME,
|
|
8
|
-
type BackupMetadata,
|
|
9
|
-
BackupMetadataSchema
|
|
10
|
-
} from "./backupMetadataSchema.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Checks if backup tracking table exists in database
|
|
14
|
-
*/
|
|
15
|
-
async function tableExists(
|
|
16
|
-
db: DatabaseAdapter,
|
|
17
|
-
databaseId: string
|
|
18
|
-
): Promise<boolean> {
|
|
19
|
-
try {
|
|
20
|
-
await db.getTable({ databaseId, tableId: BACKUP_TABLE_ID });
|
|
21
|
-
return true;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates the backup tracking table in the specified database
|
|
29
|
-
*/
|
|
30
|
-
export async function createBackupTrackingTable(
|
|
31
|
-
db: DatabaseAdapter,
|
|
32
|
-
databaseId: string
|
|
33
|
-
): Promise<void> {
|
|
34
|
-
// Check if table already exists
|
|
35
|
-
const exists = await tableExists(db, databaseId);
|
|
36
|
-
if (exists) {
|
|
37
|
-
logger.debug("Backup tracking table already exists", {
|
|
38
|
-
databaseId,
|
|
39
|
-
tableId: BACKUP_TABLE_ID
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
logger.info("Creating backup tracking table", {
|
|
45
|
-
databaseId,
|
|
46
|
-
tableId: BACKUP_TABLE_ID
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Create table
|
|
50
|
-
await tryAwaitWithRetry(async () => {
|
|
51
|
-
await db.createTable({
|
|
52
|
-
databaseId,
|
|
53
|
-
id: BACKUP_TABLE_ID,
|
|
54
|
-
name: BACKUP_TABLE_NAME
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Create attributes
|
|
59
|
-
const attributes = [
|
|
60
|
-
{
|
|
61
|
-
key: "backupId",
|
|
62
|
-
type: "string" as const,
|
|
63
|
-
size: 50,
|
|
64
|
-
required: true
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
key: "databaseId",
|
|
68
|
-
type: "string" as const,
|
|
69
|
-
size: 50,
|
|
70
|
-
required: true
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
key: "sizeBytes",
|
|
74
|
-
type: "integer" as const,
|
|
75
|
-
required: true
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
key: "collections",
|
|
79
|
-
type: "integer" as const,
|
|
80
|
-
required: true
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
key: "documents",
|
|
84
|
-
type: "integer" as const,
|
|
85
|
-
required: true
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
key: "format",
|
|
89
|
-
type: "enum" as const,
|
|
90
|
-
elements: ["json", "zip"],
|
|
91
|
-
required: true
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
key: "status",
|
|
95
|
-
type: "enum" as const,
|
|
96
|
-
elements: ["completed", "failed"],
|
|
97
|
-
required: true
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
key: "error",
|
|
101
|
-
type: "string" as const,
|
|
102
|
-
size: 10000,
|
|
103
|
-
required: false
|
|
104
|
-
}
|
|
105
|
-
];
|
|
106
|
-
|
|
107
|
-
for (const attr of attributes) {
|
|
108
|
-
await tryAwaitWithRetry(async () => {
|
|
109
|
-
await db.createAttribute({
|
|
110
|
-
databaseId,
|
|
111
|
-
tableId: BACKUP_TABLE_ID,
|
|
112
|
-
...attr
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
logger.info("Backup tracking table created successfully", {
|
|
118
|
-
databaseId,
|
|
119
|
-
tableId: BACKUP_TABLE_ID
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Records backup metadata in the tracking table
|
|
125
|
-
*/
|
|
126
|
-
export async function recordBackup(
|
|
127
|
-
db: DatabaseAdapter,
|
|
128
|
-
databaseId: string,
|
|
129
|
-
metadata: Omit<BackupMetadata, '$id' | '$createdAt' | '$updatedAt'>
|
|
130
|
-
): Promise<BackupMetadata> {
|
|
131
|
-
// Ensure tracking table exists
|
|
132
|
-
await createBackupTrackingTable(db, databaseId);
|
|
133
|
-
|
|
134
|
-
// Create backup record
|
|
135
|
-
const result = await db.createRow({
|
|
136
|
-
databaseId,
|
|
137
|
-
tableId: BACKUP_TABLE_ID,
|
|
138
|
-
id: ID.unique(),
|
|
139
|
-
data: {
|
|
140
|
-
backupId: metadata.backupId,
|
|
141
|
-
databaseId: metadata.databaseId,
|
|
142
|
-
sizeBytes: metadata.sizeBytes,
|
|
143
|
-
collections: metadata.collections,
|
|
144
|
-
documents: metadata.documents,
|
|
145
|
-
format: metadata.format,
|
|
146
|
-
status: metadata.status,
|
|
147
|
-
error: metadata.error
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
logger.info("Recorded backup metadata", {
|
|
152
|
-
backupId: metadata.backupId,
|
|
153
|
-
databaseId: metadata.databaseId,
|
|
154
|
-
format: metadata.format
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
return result.data as BackupMetadata;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Lists all backups for a database, sorted by creation date (newest first)
|
|
162
|
-
*/
|
|
163
|
-
export async function listBackups(
|
|
164
|
-
db: DatabaseAdapter,
|
|
165
|
-
databaseId: string
|
|
166
|
-
): Promise<BackupMetadata[]> {
|
|
167
|
-
try {
|
|
168
|
-
const result = await db.listRows({
|
|
169
|
-
databaseId,
|
|
170
|
-
tableId: BACKUP_TABLE_ID,
|
|
171
|
-
queries: [
|
|
172
|
-
Query.orderDesc("$createdAt"),
|
|
173
|
-
Query.limit(100) // Limit to last 100 backups
|
|
174
|
-
]
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return (result.rows || []) as BackupMetadata[];
|
|
178
|
-
} catch (error) {
|
|
179
|
-
// Table might not exist yet
|
|
180
|
-
logger.debug("No backup tracking table found", { databaseId });
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Gets the most recent backup for a database
|
|
187
|
-
*/
|
|
188
|
-
export async function getLastBackup(
|
|
189
|
-
db: DatabaseAdapter,
|
|
190
|
-
databaseId: string
|
|
191
|
-
): Promise<BackupMetadata | null> {
|
|
192
|
-
try {
|
|
193
|
-
const result = await db.listRows({
|
|
194
|
-
databaseId,
|
|
195
|
-
tableId: BACKUP_TABLE_ID,
|
|
196
|
-
queries: [
|
|
197
|
-
Query.orderDesc("$createdAt"),
|
|
198
|
-
Query.limit(1)
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
if (result.rows && result.rows.length > 0) {
|
|
203
|
-
return result.rows[0] as BackupMetadata;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return null;
|
|
207
|
-
} catch (error) {
|
|
208
|
-
logger.debug("No backup found or table doesn't exist", { databaseId });
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { MessageFormatter } from 'appwrite-utils-helpers';
|
|
4
|
-
|
|
5
|
-
export interface DestructiveOperationOptions {
|
|
6
|
-
operation: string;
|
|
7
|
-
targets: string[];
|
|
8
|
-
consequences?: string[];
|
|
9
|
-
requireExplicitConfirmation?: boolean;
|
|
10
|
-
confirmationText?: string;
|
|
11
|
-
skipConfirmation?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface BackupPromptOptions {
|
|
15
|
-
operation: string;
|
|
16
|
-
targets: string[];
|
|
17
|
-
recommendBackup?: boolean;
|
|
18
|
-
backupMessage?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class ConfirmationDialogs {
|
|
22
|
-
/**
|
|
23
|
-
* Shows a confirmation dialog for destructive operations
|
|
24
|
-
*/
|
|
25
|
-
static async confirmDestructiveOperation(options: DestructiveOperationOptions): Promise<boolean> {
|
|
26
|
-
if (options.skipConfirmation) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
MessageFormatter.warning(`You are about to perform a destructive operation:`, { skipLogging: true });
|
|
31
|
-
MessageFormatter.error(`Operation: ${options.operation}`, undefined, { skipLogging: true });
|
|
32
|
-
MessageFormatter.warning(`Targets: ${options.targets.join(", ")}`, { skipLogging: true });
|
|
33
|
-
|
|
34
|
-
if (options.consequences && options.consequences.length > 0) {
|
|
35
|
-
MessageFormatter.error("This will:", undefined, { skipLogging: true });
|
|
36
|
-
options.consequences.forEach(consequence => {
|
|
37
|
-
MessageFormatter.error(` • ${consequence}`, undefined, { skipLogging: true });
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
MessageFormatter.error("⚠️ THIS ACTION CANNOT BE UNDONE!", undefined, { skipLogging: true });
|
|
42
|
-
|
|
43
|
-
if (options.requireExplicitConfirmation && options.confirmationText) {
|
|
44
|
-
const { confirmation } = await inquirer.prompt([{
|
|
45
|
-
type: 'input',
|
|
46
|
-
name: 'confirmation',
|
|
47
|
-
message: chalk.red(`Type "${options.confirmationText}" to confirm:`),
|
|
48
|
-
validate: (input: string) => {
|
|
49
|
-
return input === options.confirmationText ||
|
|
50
|
-
chalk.red(`Please type exactly: ${options.confirmationText}`);
|
|
51
|
-
}
|
|
52
|
-
}]);
|
|
53
|
-
|
|
54
|
-
return confirmation === options.confirmationText;
|
|
55
|
-
} else {
|
|
56
|
-
const { confirmed } = await inquirer.prompt([{
|
|
57
|
-
type: 'confirm',
|
|
58
|
-
name: 'confirmed',
|
|
59
|
-
message: chalk.red('Are you absolutely sure you want to continue?'),
|
|
60
|
-
default: false
|
|
61
|
-
}]);
|
|
62
|
-
|
|
63
|
-
return confirmed;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Prompts user about creating a backup before a destructive operation
|
|
69
|
-
*/
|
|
70
|
-
static async promptForBackup(options: BackupPromptOptions): Promise<'yes' | 'no' | 'skip'> {
|
|
71
|
-
const message = options.backupMessage ||
|
|
72
|
-
`Create a backup before performing ${options.operation} on: ${options.targets.join(", ")}?`;
|
|
73
|
-
|
|
74
|
-
MessageFormatter.info("🛡️ Backup Recommendation", { skipLogging: true });
|
|
75
|
-
if (options.recommendBackup !== false) {
|
|
76
|
-
MessageFormatter.warning("It's strongly recommended to create a backup before proceeding.", { skipLogging: true });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { choice } = await inquirer.prompt([{
|
|
80
|
-
type: 'list',
|
|
81
|
-
name: 'choice',
|
|
82
|
-
message,
|
|
83
|
-
choices: [
|
|
84
|
-
{ name: '🛡️ Yes, create backup first', value: 'yes' },
|
|
85
|
-
{ name: '⚠️ No, proceed without backup', value: 'no' },
|
|
86
|
-
{ name: '❌ Cancel operation', value: 'skip' }
|
|
87
|
-
],
|
|
88
|
-
default: 'yes'
|
|
89
|
-
}]);
|
|
90
|
-
|
|
91
|
-
return choice;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Shows a final confirmation before proceeding with an operation
|
|
96
|
-
*/
|
|
97
|
-
static async finalConfirmation(operation: string, details?: string[]): Promise<boolean> {
|
|
98
|
-
MessageFormatter.success(`Ready to perform: ${operation}`, { skipLogging: true });
|
|
99
|
-
|
|
100
|
-
if (details && details.length > 0) {
|
|
101
|
-
MessageFormatter.debug("Details:", undefined, { skipLogging: true });
|
|
102
|
-
details.forEach(detail => {
|
|
103
|
-
MessageFormatter.debug(` • ${detail}`, undefined, { skipLogging: true });
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const { proceed } = await inquirer.prompt([{
|
|
108
|
-
type: 'confirm',
|
|
109
|
-
name: 'proceed',
|
|
110
|
-
message: 'Proceed with this operation?',
|
|
111
|
-
default: true
|
|
112
|
-
}]);
|
|
113
|
-
|
|
114
|
-
return proceed;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Specialized confirmation for database wiping
|
|
119
|
-
*/
|
|
120
|
-
static async confirmDatabaseWipe(databaseNames: string[], options: {
|
|
121
|
-
includeStorage?: boolean;
|
|
122
|
-
includeUsers?: boolean;
|
|
123
|
-
skipConfirmation?: boolean;
|
|
124
|
-
} = {}): Promise<boolean> {
|
|
125
|
-
const consequences = [
|
|
126
|
-
"Delete all documents in the specified databases",
|
|
127
|
-
"Remove all collections and their data",
|
|
128
|
-
];
|
|
129
|
-
|
|
130
|
-
if (options.includeStorage) {
|
|
131
|
-
consequences.push("Delete all files in associated storage buckets");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (options.includeUsers) {
|
|
135
|
-
consequences.push("Delete all user accounts");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return this.confirmDestructiveOperation({
|
|
139
|
-
operation: "Database Wipe",
|
|
140
|
-
targets: databaseNames,
|
|
141
|
-
consequences,
|
|
142
|
-
requireExplicitConfirmation: true,
|
|
143
|
-
confirmationText: "DELETE ALL DATA",
|
|
144
|
-
skipConfirmation: options.skipConfirmation,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Specialized confirmation for collection wiping
|
|
150
|
-
*/
|
|
151
|
-
static async confirmCollectionWipe(
|
|
152
|
-
databaseName: string,
|
|
153
|
-
collectionNames: string[],
|
|
154
|
-
options: { skipConfirmation?: boolean } = {}
|
|
155
|
-
): Promise<boolean> {
|
|
156
|
-
return this.confirmDestructiveOperation({
|
|
157
|
-
operation: "Collection Wipe",
|
|
158
|
-
targets: collectionNames.map(name => `${databaseName}.${name}`),
|
|
159
|
-
consequences: [
|
|
160
|
-
"Delete all documents in the specified collections",
|
|
161
|
-
"Keep the collection structure intact",
|
|
162
|
-
],
|
|
163
|
-
requireExplicitConfirmation: collectionNames.length > 5,
|
|
164
|
-
confirmationText: "DELETE DOCUMENTS",
|
|
165
|
-
skipConfirmation: options.skipConfirmation,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Specialized confirmation for function deployment
|
|
171
|
-
*/
|
|
172
|
-
static async confirmFunctionDeployment(
|
|
173
|
-
functionNames: string[],
|
|
174
|
-
options: {
|
|
175
|
-
isProduction?: boolean;
|
|
176
|
-
hasBreakingChanges?: boolean;
|
|
177
|
-
skipConfirmation?: boolean;
|
|
178
|
-
} = {}
|
|
179
|
-
): Promise<boolean> {
|
|
180
|
-
if (options.skipConfirmation) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const consequences = ["Replace existing function code"];
|
|
185
|
-
|
|
186
|
-
if (options.isProduction) {
|
|
187
|
-
consequences.push("Affect production environment");
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (options.hasBreakingChanges) {
|
|
191
|
-
consequences.push("Potentially break existing integrations");
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return this.confirmDestructiveOperation({
|
|
195
|
-
operation: "Function Deployment",
|
|
196
|
-
targets: functionNames,
|
|
197
|
-
consequences: consequences.length > 1 ? consequences : undefined,
|
|
198
|
-
requireExplicitConfirmation: options.isProduction || options.hasBreakingChanges,
|
|
199
|
-
confirmationText: options.isProduction ? "DEPLOY TO PRODUCTION" : "DEPLOY",
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Shows operation summary and asks for final confirmation
|
|
205
|
-
*/
|
|
206
|
-
static async showOperationSummary(
|
|
207
|
-
title: string,
|
|
208
|
-
summary: Record<string, string | number | string[]>,
|
|
209
|
-
options: {
|
|
210
|
-
confirmationRequired?: boolean;
|
|
211
|
-
warningMessage?: string;
|
|
212
|
-
} = {}
|
|
213
|
-
): Promise<boolean> {
|
|
214
|
-
MessageFormatter.section(`${title} Summary`);
|
|
215
|
-
|
|
216
|
-
Object.entries(summary).forEach(([key, value]) => {
|
|
217
|
-
const formattedKey = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
|
|
218
|
-
|
|
219
|
-
if (Array.isArray(value)) {
|
|
220
|
-
MessageFormatter.info(`● ${formattedKey}:`, { skipLogging: true });
|
|
221
|
-
value.forEach(item => {
|
|
222
|
-
MessageFormatter.debug(` • ${item}`, undefined, { skipLogging: true });
|
|
223
|
-
});
|
|
224
|
-
} else {
|
|
225
|
-
MessageFormatter.info(`● ${formattedKey}: ${String(value)}`, { skipLogging: true });
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
if (options.warningMessage) {
|
|
230
|
-
MessageFormatter.warning(`⚠️ ${options.warningMessage}`, { skipLogging: true });
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (options.confirmationRequired !== false) {
|
|
234
|
-
const { confirmed } = await inquirer.prompt([{
|
|
235
|
-
type: 'confirm',
|
|
236
|
-
name: 'confirmed',
|
|
237
|
-
message: 'Continue with this operation?',
|
|
238
|
-
default: true
|
|
239
|
-
}]);
|
|
240
|
-
|
|
241
|
-
return confirmed;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Interactive selection with confirmation
|
|
249
|
-
*/
|
|
250
|
-
static async selectWithConfirmation<T>(
|
|
251
|
-
items: T[],
|
|
252
|
-
options: {
|
|
253
|
-
message: string;
|
|
254
|
-
displayProperty?: keyof T;
|
|
255
|
-
multiSelect?: boolean;
|
|
256
|
-
confirmMessage?: string;
|
|
257
|
-
validator?: (selection: T[]) => string | true;
|
|
258
|
-
}
|
|
259
|
-
): Promise<T[]> {
|
|
260
|
-
const choices = items.map((item, index) => ({
|
|
261
|
-
name: options.displayProperty ? String(item[options.displayProperty]) : String(item),
|
|
262
|
-
value: item,
|
|
263
|
-
}));
|
|
264
|
-
|
|
265
|
-
const prompt = options.multiSelect ? 'checkbox' : 'list';
|
|
266
|
-
const { selection } = await inquirer.prompt([{
|
|
267
|
-
type: prompt,
|
|
268
|
-
name: 'selection',
|
|
269
|
-
message: options.message,
|
|
270
|
-
choices,
|
|
271
|
-
validate: options.validator ? (input: T[]) => {
|
|
272
|
-
const result = options.validator!(Array.isArray(input) ? input : [input]);
|
|
273
|
-
return result;
|
|
274
|
-
} : undefined,
|
|
275
|
-
}]);
|
|
276
|
-
|
|
277
|
-
const selectedItems = Array.isArray(selection) ? selection : [selection];
|
|
278
|
-
|
|
279
|
-
if (options.confirmMessage) {
|
|
280
|
-
const confirmMessage = options.confirmMessage.replace(
|
|
281
|
-
'{count}',
|
|
282
|
-
selectedItems.length.toString()
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
const { confirmed } = await inquirer.prompt([{
|
|
286
|
-
type: 'confirm',
|
|
287
|
-
name: 'confirmed',
|
|
288
|
-
message: confirmMessage,
|
|
289
|
-
default: true
|
|
290
|
-
}]);
|
|
291
|
-
|
|
292
|
-
if (!confirmed) {
|
|
293
|
-
return [];
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return selectedItems;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Confirms overwriting an existing file or directory
|
|
302
|
-
*/
|
|
303
|
-
static async confirmOverwrite(target: string): Promise<boolean> {
|
|
304
|
-
const { confirmed } = await inquirer.prompt([{
|
|
305
|
-
type: 'confirm',
|
|
306
|
-
name: 'confirmed',
|
|
307
|
-
message: chalk.yellow(`${target} already exists. Overwrite?`),
|
|
308
|
-
default: false
|
|
309
|
-
}]);
|
|
310
|
-
|
|
311
|
-
return confirmed;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Confirms removal of a file
|
|
316
|
-
*/
|
|
317
|
-
static async confirmRemoval(target: string): Promise<boolean> {
|
|
318
|
-
const { confirmed } = await inquirer.prompt([{
|
|
319
|
-
type: 'confirm',
|
|
320
|
-
name: 'confirmed',
|
|
321
|
-
message: chalk.red(target),
|
|
322
|
-
default: false
|
|
323
|
-
}]);
|
|
324
|
-
|
|
325
|
-
return confirmed;
|
|
326
|
-
}
|
|
327
|
-
}
|