@solcreek/cli 0.4.28 → 0.4.29

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.
@@ -163,7 +163,7 @@ const migrateCommand = defineCommand({
163
163
  },
164
164
  dir: {
165
165
  type: "string",
166
- description: "Migration directory path. Default: auto-detect drizzle/, drizzle/migrations/, migrations/, sql/",
166
+ description: "Migration directory path. Default: auto-detect drizzle/, drizzle/migrations/, prisma/migrations/, migrations/, sql/",
167
167
  required: false,
168
168
  },
169
169
  "dry-run": {
@@ -198,7 +198,7 @@ const migrateCommand = defineCommand({
198
198
  if (!migrationDir) {
199
199
  const msg = args.dir
200
200
  ? `Migration directory not found: ${args.dir}`
201
- : "No migration directory found. Looked for: drizzle/, drizzle/migrations/, migrations/, sql/. Use --dir to specify.";
201
+ : "No migration directory found. Looked for: drizzle/, drizzle/migrations/, prisma/migrations/, migrations/, sql/. Use --dir to specify.";
202
202
  if (jsonMode)
203
203
  jsonOutput({ ok: false, error: "no_migration_dir", message: msg }, 1);
204
204
  consola.error(msg);
@@ -6,8 +6,8 @@
6
6
  */
7
7
  /**
8
8
  * Find the migration directory relative to cwd.
9
- * Returns the absolute path of the first candidate that exists and
10
- * contains at least one .sql file, or null if none found.
9
+ * Returns the absolute path of the first candidate that holds migrations
10
+ * (flat `.sql` or Prisma's nested `<name>/migration.sql`), or null.
11
11
  */
12
12
  export declare function detectMigrationDir(cwd: string): string | null;
13
13
  export interface MigrationFile {
@@ -17,8 +17,13 @@ export interface MigrationFile {
17
17
  path: string;
18
18
  }
19
19
  /**
20
- * Read .sql files from a directory, sorted lexicographically.
21
- * Non-.sql files and empty .sql files are skipped.
20
+ * Read migrations from a directory in either layout, sorted lexicographically
21
+ * by name (Drizzle's `NNNN_` prefixes and Prisma's `<timestamp>_` prefixes both
22
+ * sort chronologically). Empty migrations are skipped.
23
+ *
24
+ * - flat: each `.sql` file is a migration; name = file name (e.g. `0001_init.sql`)
25
+ * - nested: each `<name>/migration.sql` is a migration; name = subdir name
26
+ * (e.g. `20260614120000_init`) — the identifier Prisma tracks
22
27
  */
23
28
  export declare function parseMigrationFiles(dir: string): MigrationFile[];
24
29
  /**
@@ -10,33 +10,49 @@ import { join, resolve } from "node:path";
10
10
  const CANDIDATE_DIRS = [
11
11
  "drizzle",
12
12
  "drizzle/migrations",
13
+ "prisma/migrations",
13
14
  "migrations",
14
15
  "sql",
15
16
  ];
17
+ /**
18
+ * Whether a directory holds migrations in either supported layout:
19
+ * - flat: `.sql` files directly in the dir (Drizzle `drizzle-kit generate`,
20
+ * plain SQL dirs)
21
+ * - nested: `<name>/migration.sql` per migration (Prisma `prisma migrate`)
22
+ */
23
+ function hasMigrations(dir) {
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir);
27
+ }
28
+ catch {
29
+ return false; // Permission error or not a directory.
30
+ }
31
+ if (entries.some((f) => f.endsWith(".sql")))
32
+ return true;
33
+ return entries.some((f) => existsSync(join(dir, f, "migration.sql")));
34
+ }
16
35
  /**
17
36
  * Find the migration directory relative to cwd.
18
- * Returns the absolute path of the first candidate that exists and
19
- * contains at least one .sql file, or null if none found.
37
+ * Returns the absolute path of the first candidate that holds migrations
38
+ * (flat `.sql` or Prisma's nested `<name>/migration.sql`), or null.
20
39
  */
21
40
  export function detectMigrationDir(cwd) {
22
41
  for (const dir of CANDIDATE_DIRS) {
23
42
  const abs = resolve(cwd, dir);
24
- if (existsSync(abs)) {
25
- try {
26
- const files = readdirSync(abs);
27
- if (files.some((f) => f.endsWith(".sql")))
28
- return abs;
29
- }
30
- catch {
31
- // Permission error or not a directory — skip
32
- }
33
- }
43
+ if (existsSync(abs) && hasMigrations(abs))
44
+ return abs;
34
45
  }
35
46
  return null;
36
47
  }
37
48
  /**
38
- * Read .sql files from a directory, sorted lexicographically.
39
- * Non-.sql files and empty .sql files are skipped.
49
+ * Read migrations from a directory in either layout, sorted lexicographically
50
+ * by name (Drizzle's `NNNN_` prefixes and Prisma's `<timestamp>_` prefixes both
51
+ * sort chronologically). Empty migrations are skipped.
52
+ *
53
+ * - flat: each `.sql` file is a migration; name = file name (e.g. `0001_init.sql`)
54
+ * - nested: each `<name>/migration.sql` is a migration; name = subdir name
55
+ * (e.g. `20260614120000_init`) — the identifier Prisma tracks
40
56
  */
41
57
  export function parseMigrationFiles(dir) {
42
58
  let entries;
@@ -46,10 +62,19 @@ export function parseMigrationFiles(dir) {
46
62
  catch {
47
63
  return [];
48
64
  }
49
- return entries
50
- .filter((f) => f.endsWith(".sql"))
51
- .sort()
52
- .map((name) => ({ name, path: join(dir, name) }))
65
+ const files = [];
66
+ for (const name of entries) {
67
+ if (name.endsWith(".sql")) {
68
+ files.push({ name, path: join(dir, name) });
69
+ continue;
70
+ }
71
+ // Prisma nests each migration as `<name>/migration.sql`.
72
+ const nested = join(dir, name, "migration.sql");
73
+ if (existsSync(nested))
74
+ files.push({ name, path: nested });
75
+ }
76
+ return files
77
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
53
78
  .filter((f) => {
54
79
  try {
55
80
  const content = readFileSync(f.path, "utf-8").trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solcreek/cli",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "description": "CLI for the Creek deployment platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",