@zerotal/orm 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -102,13 +102,13 @@ import { Migration, Schema } from "@zerotal/orm";
102
102
 
103
103
  export default class CreatePostsTable extends Migration {
104
104
  async up(): Promise<void> {
105
- await Schema.create("posts", (t) => {
106
- t.increments("id");
107
- t.integer("user_id").index();
108
- t.string("title");
109
- t.text("body");
110
- t.softDeletes();
111
- t.timestamps();
105
+ await Schema.create("posts", (table) => {
106
+ table.increments("id");
107
+ table.integer("user_id").index();
108
+ table.string("title");
109
+ table.text("body");
110
+ table.softDeletes();
111
+ table.timestamps();
112
112
  });
113
113
  }
114
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerotal/orm",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "maturity": "stable",
6
6
  "private": false,
@@ -30,8 +30,8 @@
30
30
  "typecheck": "tsc --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "@zerotal/core": "1.0.0",
34
- "@zerotal/validator": "1.0.0"
33
+ "@zerotal/core": "1.0.2",
34
+ "@zerotal/validator": "1.0.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^5.8.0"
@@ -1,3 +1,5 @@
1
+ import { resolve } from "node:path";
2
+ import { pathToFileURL } from "node:url";
1
3
  import type { SQLInstance } from "../db/sql-types.ts";
2
4
  import type { Migration } from "./Migration.ts";
3
5
  import { MigrationError } from "../errors/MigrationError.ts";
@@ -337,7 +339,13 @@ export class MigrationRunner {
337
339
 
338
340
  const entries: MigrationEntry[] = [];
339
341
  for (const file of files) {
340
- const fullPath = `${dir}/${file}`;
342
+ // Resolved to a file:// URL, not joined as a string. `database/migrations`
343
+ // is a perfectly ordinary way to configure this directory, and importing
344
+ // `database/migrations/0001_x.ts` verbatim asks the module resolver for a
345
+ // *package* by that name — which fails with "Cannot find module" even
346
+ // though `readdirSync` just listed the file. A URL also keeps Windows
347
+ // drive letters from being read as a protocol.
348
+ const fullPath = pathToFileURL(resolve(dir, file)).href;
341
349
  // Dynamic import — each migration file must have a default export
342
350
  const mod = (await import(fullPath)) as { default: new () => Migration };
343
351
  const Ctor = mod.default;
@@ -57,8 +57,8 @@ export async function synchronizeSchema(options: SynchronizeOptions = {}): Promi
57
57
  const diff = await SchemaDiffer.diff(ModelInspector.all());
58
58
 
59
59
  for (const { schema } of diff.newTables) {
60
- await Schema.createIfNotExists(schema.table, (t) => {
61
- const table = t as unknown as TableBuilder;
60
+ await Schema.createIfNotExists(schema.table, (blueprint) => {
61
+ const table = blueprint as unknown as TableBuilder;
62
62
  table.increments(columnDbName(schema.primaryKey));
63
63
  for (const col of schema.columns) {
64
64
  if (col.primary) continue; // increments() covers the PK
@@ -76,8 +76,8 @@ export async function synchronizeSchema(options: SynchronizeOptions = {}): Promi
76
76
  byTable.set(nc.table, bucket);
77
77
  }
78
78
  for (const [table, cols] of byTable) {
79
- await Schema.table(table, (t) => {
80
- const tb = t as unknown as TableBuilder;
79
+ await Schema.table(table, (blueprint) => {
80
+ const tb = blueprint as unknown as TableBuilder;
81
81
  for (const col of cols) applyColumn(tb, col);
82
82
  });
83
83
  }
@@ -94,8 +94,8 @@ export async function synchronizeSchema(options: SynchronizeOptions = {}): Promi
94
94
  console.warn(
95
95
  `[Zerotal] synchronize (disruptive): dropping ${table}.{${names.join(", ")}} - data will be lost.`,
96
96
  );
97
- await Schema.table(table, (t) => {
98
- (t as unknown as TableBuilder).dropColumn(...names);
97
+ await Schema.table(table, (blueprint) => {
98
+ (blueprint as unknown as TableBuilder).dropColumn(...names);
99
99
  });
100
100
  }
101
101
  }