@ftschopp/dynatable-migrations 1.2.6 → 1.3.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +12 -0
  3. package/dist/cli.js +21 -1
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/create.js +1 -1
  6. package/dist/commands/create.js.map +1 -1
  7. package/dist/commands/down.d.ts +1 -1
  8. package/dist/commands/down.d.ts.map +1 -1
  9. package/dist/commands/down.js +61 -1
  10. package/dist/commands/down.js.map +1 -1
  11. package/dist/commands/unlock.d.ts +8 -0
  12. package/dist/commands/unlock.d.ts.map +1 -0
  13. package/dist/commands/unlock.js +87 -0
  14. package/dist/commands/unlock.js.map +1 -0
  15. package/dist/core/config.d.ts.map +1 -1
  16. package/dist/core/config.js +14 -1
  17. package/dist/core/config.js.map +1 -1
  18. package/dist/core/loader.d.ts +22 -1
  19. package/dist/core/loader.d.ts.map +1 -1
  20. package/dist/core/loader.js +56 -6
  21. package/dist/core/loader.js.map +1 -1
  22. package/dist/core/runner.d.ts.map +1 -1
  23. package/dist/core/runner.js +29 -8
  24. package/dist/core/runner.js.map +1 -1
  25. package/dist/core/tracker.d.ts +18 -3
  26. package/dist/core/tracker.d.ts.map +1 -1
  27. package/dist/core/tracker.js +60 -23
  28. package/dist/core/tracker.js.map +1 -1
  29. package/dist/types/index.d.ts +7 -2
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/package.json +35 -4
  32. package/.gitkeep +0 -0
  33. package/jest.config.js +0 -8
  34. package/migrations/.gitkeep +0 -0
  35. package/src/cli-utils.test.ts +0 -45
  36. package/src/cli-utils.ts +0 -18
  37. package/src/cli.ts +0 -110
  38. package/src/commands/create.ts +0 -111
  39. package/src/commands/down.ts +0 -26
  40. package/src/commands/init.ts +0 -37
  41. package/src/commands/status.ts +0 -75
  42. package/src/commands/up.ts +0 -26
  43. package/src/core/client.ts +0 -24
  44. package/src/core/config.ts +0 -140
  45. package/src/core/errors.ts +0 -55
  46. package/src/core/loader.ts +0 -256
  47. package/src/core/lock-heartbeat.test.ts +0 -78
  48. package/src/core/lock-heartbeat.ts +0 -48
  49. package/src/core/runner.test.ts +0 -51
  50. package/src/core/runner.ts +0 -315
  51. package/src/core/semver.test.ts +0 -33
  52. package/src/core/semver.ts +0 -26
  53. package/src/core/tracker.test.ts +0 -281
  54. package/src/core/tracker.ts +0 -559
  55. package/src/index.ts +0 -25
  56. package/src/templates/migration.ts +0 -92
  57. package/src/types/index.ts +0 -220
  58. package/tsconfig.json +0 -19
@@ -1,220 +0,0 @@
1
- import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
2
- import type {
3
- ScanCommand,
4
- QueryCommand,
5
- GetCommand,
6
- PutCommand,
7
- UpdateCommand,
8
- DeleteCommand,
9
- BatchGetCommand,
10
- BatchWriteCommand,
11
- TransactWriteCommand,
12
- TransactGetCommand,
13
- } from '@aws-sdk/lib-dynamodb';
14
-
15
- /**
16
- * DynamoDB commands available in migrations
17
- */
18
- export interface DynamoDBCommands {
19
- ScanCommand: typeof ScanCommand;
20
- QueryCommand: typeof QueryCommand;
21
- GetCommand: typeof GetCommand;
22
- PutCommand: typeof PutCommand;
23
- UpdateCommand: typeof UpdateCommand;
24
- DeleteCommand: typeof DeleteCommand;
25
- BatchGetCommand: typeof BatchGetCommand;
26
- BatchWriteCommand: typeof BatchWriteCommand;
27
- TransactWriteCommand: typeof TransactWriteCommand;
28
- TransactGetCommand: typeof TransactGetCommand;
29
- }
30
-
31
- /**
32
- * Migration context provided to up/down functions
33
- */
34
- export interface MigrationContext {
35
- client: DynamoDBDocumentClient;
36
- tableName: string;
37
- tracker: MigrationTracker;
38
- config: MigrationConfig;
39
- dynamodb: DynamoDBCommands;
40
- }
41
-
42
- /**
43
- * Schema change record for tracking evolution
44
- */
45
- export interface SchemaChange {
46
- entity: string;
47
- changes: {
48
- added?: string[];
49
- removed?: string[];
50
- modified?: Array<{
51
- field: string;
52
- from: any;
53
- to: any;
54
- }>;
55
- };
56
- }
57
-
58
- /**
59
- * Migration definition
60
- */
61
- export interface Migration {
62
- version: string;
63
- name: string;
64
- description?: string;
65
-
66
- // Optional schema snapshot for documentation
67
- schema?: Record<string, any>;
68
-
69
- // Migration functions
70
- up: (context: MigrationContext) => Promise<void>;
71
- down: (context: MigrationContext) => Promise<void>;
72
- }
73
-
74
- /**
75
- * Migration record stored in DynamoDB
76
- */
77
- export interface MigrationRecord {
78
- PK: string; // "SCHEMA#VERSION"
79
- SK: string; // "v0001"
80
- version: string;
81
- name: string;
82
- description?: string;
83
- timestamp: string;
84
- appliedAt: string;
85
- status: 'applied' | 'rolled_back' | 'failed';
86
- schemaDefinition?: Record<string, any>;
87
- schemaChanges?: SchemaChange[];
88
- checksum?: string; // Hash of migration file
89
- error?: string; // Error message if failed
90
- }
91
-
92
- /**
93
- * Current schema pointer record
94
- */
95
- export interface CurrentSchemaRecord {
96
- GSI1PK: string; // "SCHEMA#CURRENT"
97
- GSI1SK: string; // Current version
98
- PK: string;
99
- SK: string;
100
- currentVersion: string;
101
- updatedAt: string;
102
- }
103
-
104
- /**
105
- * Migration configuration
106
- */
107
- export interface MigrationConfig {
108
- tableName: string;
109
- client: {
110
- endpoint?: string;
111
- region: string;
112
- credentials?: {
113
- accessKeyId: string;
114
- secretAccessKey: string;
115
- };
116
- };
117
- migrationsDir?: string;
118
- trackingPrefix?: string; // Default: "_SCHEMA#VERSION"
119
- gsi1Name?: string; // Default: "GSI1"
120
- /**
121
- * How long an acquired migration lock stays valid before another worker
122
- * can take it over, in seconds. The runner sends a heartbeat every
123
- * `lockTtlSeconds / 3` to extend it. Default: 300 (5 minutes).
124
- */
125
- lockTtlSeconds?: number;
126
- }
127
-
128
- /**
129
- * Migration tracker interface
130
- */
131
- export interface MigrationTracker {
132
- /**
133
- * Initialize migration tracking table/items if needed
134
- */
135
- initialize(): Promise<void>;
136
-
137
- /**
138
- * Get all applied migrations
139
- */
140
- getAppliedMigrations(): Promise<MigrationRecord[]>;
141
-
142
- /**
143
- * Get current schema version
144
- */
145
- getCurrentVersion(): Promise<string | null>;
146
-
147
- /**
148
- * Acquire a distributed lock
149
- */
150
- acquireLock(): Promise<boolean>;
151
-
152
- /**
153
- * Release the distributed lock
154
- */
155
- releaseLock(): Promise<void>;
156
-
157
- /**
158
- * Extend the lock's expiration. Throws `ConditionalCheckFailedException`
159
- * if the lock has already been taken by someone else.
160
- */
161
- refreshLock(): Promise<void>;
162
-
163
- /**
164
- * Mark migration as applied
165
- */
166
- markAsApplied(
167
- version: string,
168
- name: string,
169
- schemaDefinition?: Record<string, any>,
170
- schemaChanges?: SchemaChange[],
171
- checksum?: string
172
- ): Promise<void>;
173
-
174
- /**
175
- * Mark migration as rolled back
176
- */
177
- markAsRolledBack(version: string): Promise<void>;
178
-
179
- /**
180
- * Mark migration as failed
181
- */
182
- markAsFailed(version: string, error: string): Promise<void>;
183
-
184
- /**
185
- * Record schema changes
186
- */
187
- recordSchemaChange(change: SchemaChange): Promise<void>;
188
-
189
- /**
190
- * Get migration by version
191
- */
192
- getMigration(version: string): Promise<MigrationRecord | null>;
193
-
194
- /**
195
- * Check if migration was applied
196
- */
197
- isApplied(version: string): Promise<boolean>;
198
- }
199
-
200
- /**
201
- * Migration file info
202
- */
203
- export interface MigrationFile {
204
- version: string;
205
- name: string;
206
- filePath: string;
207
- migration: Migration;
208
- checksum?: string;
209
- }
210
-
211
- /**
212
- * Migration status
213
- */
214
- export interface MigrationStatus {
215
- version: string;
216
- name: string;
217
- status: 'pending' | 'applied' | 'rolled_back' | 'failed';
218
- appliedAt?: string;
219
- error?: string;
220
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "@repo/typescript-config/base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "module": "commonjs",
7
- "target": "ES2020",
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "strict": true,
14
- "resolveJsonModule": true,
15
- "moduleResolution": "node"
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
19
- }