@dboio/cli 0.19.4 → 0.20.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.
@@ -0,0 +1,68 @@
1
+ import { readdir, rename, mkdir, rmdir, access } from 'fs/promises';
2
+ import { join } from 'path';
3
+ import { log } from '../lib/logger.js';
4
+
5
+ export const description = 'Move lib/entity/ files into lib/data_source/';
6
+
7
+ /**
8
+ * Migration 014 — Relocate entity records from lib/entity/ into lib/data_source/.
9
+ *
10
+ * Entity (table-definition) records are now co-located with data source records
11
+ * under lib/data_source/. Files keep their _entity: "entity" metadata value —
12
+ * only their directory changes.
13
+ *
14
+ * If lib/data_source/ already contains a file with the same name, the source
15
+ * file is left in place and a warning is emitted; no data is overwritten.
16
+ */
17
+ export default async function run() {
18
+ const cwd = process.cwd();
19
+ const srcDir = join(cwd, 'lib', 'entity');
20
+
21
+ // Nothing to do if lib/entity/ doesn't exist
22
+ try {
23
+ await access(srcDir);
24
+ } catch {
25
+ return;
26
+ }
27
+
28
+ const entries = await readdir(srcDir, { withFileTypes: true });
29
+ if (entries.length === 0) {
30
+ // Empty directory — just remove it
31
+ try { await rmdir(srcDir); } catch { /* ignore */ }
32
+ return;
33
+ }
34
+
35
+ const destDir = join(cwd, 'lib', 'data_source');
36
+ await mkdir(destDir, { recursive: true });
37
+
38
+ let movedCount = 0;
39
+ let skippedCount = 0;
40
+
41
+ for (const entry of entries) {
42
+ const srcPath = join(srcDir, entry.name);
43
+ const destPath = join(destDir, entry.name);
44
+
45
+ // Check for collision
46
+ try {
47
+ await access(destPath);
48
+ log.warn(` Migration 014: skipped ${entry.name} — already exists in lib/data_source/`);
49
+ skippedCount++;
50
+ continue;
51
+ } catch { /* dest absent — safe to move */ }
52
+
53
+ await rename(srcPath, destPath);
54
+ movedCount++;
55
+ }
56
+
57
+ // Remove lib/entity/ if now empty
58
+ try {
59
+ const remaining = await readdir(srcDir);
60
+ if (remaining.length === 0) {
61
+ await rmdir(srcDir);
62
+ }
63
+ } catch { /* ignore */ }
64
+
65
+ if (movedCount > 0) {
66
+ log.success(` Migration 014: moved ${movedCount} file(s) from lib/entity/ → lib/data_source/${skippedCount > 0 ? ` (${skippedCount} skipped — collision)` : ''}`);
67
+ }
68
+ }