@vibeorm/runtime 2.0.0-alpha.6 → 2.0.0-alpha.7

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/dist/adapter.d.ts CHANGED
@@ -103,7 +103,13 @@ export type DatabaseAdapter = {
103
103
  transaction<T>(fn: (txAdapter: DatabaseAdapter) => Promise<T>, options?: TransactionOptions): Promise<T>;
104
104
  /** Eagerly open/verify connectivity (pool warm-up or first connection). */
105
105
  connect(): Promise<void>;
106
- /** Gracefully close all connections. */
106
+ /**
107
+ * Gracefully close the connections open right now. NOT terminal: every
108
+ * adapter constructs its pool/connection lazily, so a query issued after
109
+ * `disconnect()` transparently opens a NEW connection and succeeds — the
110
+ * documented contract (symmetric with lazy construction, and with Prisma's
111
+ * `$disconnect()`-then-query semantics), not an accident.
112
+ */
107
113
  disconnect(): Promise<void>;
108
114
  /**
109
115
  * Convert a JS array into the driver's preferred representation for a
@@ -117,7 +123,29 @@ export type SqlExecutor = (params: {
117
123
  text: string;
118
124
  values?: unknown[];
119
125
  }) => Promise<Record<string, unknown>[]>;
120
- /** Bridge a DatabaseAdapter to the migrate package's SqlExecutor shape. */
126
+ /**
127
+ * Bridge a DatabaseAdapter to the migrate package's SqlExecutor shape.
128
+ *
129
+ * NO SESSION AFFINITY — this bridge pins nothing. Every call goes through
130
+ * `adapter.executeUnsafe`, which a pooled adapter runs on whatever connection
131
+ * the pool hands out. @vibeorm/migrate's executor contract requires the
132
+ * opposite (`packages/migrate/src/types.ts`): its session-scoped statements
133
+ * (`BEGIN`/`COMMIT`, `PRAGMA foreign_keys`, `pg_advisory_lock` / `GET_LOCK`)
134
+ * must all reach ONE session. pglite and sqlite satisfy that by construction;
135
+ * a POOLED adapter (pg, mysql, bun) used for migrate must be constructed with
136
+ * a single-connection pool (`max: 1`; mysql `connectionLimit: 1`), as the
137
+ * `vibeorm` CLI does, or the caller must pin a connection another way —
138
+ * otherwise the advisory lock is taken on one connection while each
139
+ * migration's `BEGIN` runs on another, and a driver that reaps the idle
140
+ * lock-holding connection (node-postgres does, after 10s by default) releases
141
+ * the migration lock mid-run, silently.
142
+ *
143
+ * RE-ENTRANCY HAZARD: `pg_advisory_lock` is re-entrant per SESSION, so two
144
+ * concurrent `applyMigrations` calls sharing one adapter (hence one pool) can
145
+ * both "acquire" it on the same underlying connection and get zero mutual
146
+ * exclusion — separate CLI processes never collide this way, a programmatic
147
+ * caller sharing one adapter can.
148
+ */
121
149
  export declare function toSqlExecutor(params: {
122
150
  adapter: DatabaseAdapter;
123
151
  }): SqlExecutor;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAEjF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;IAE7B;;;;OAIG;IACH,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EzG,2EAA2E;IAC3E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;;;OAMG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;CAC9C,CAAC;AAIF,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,GAAG,WAAW,CAS/E"}
package/dist/index.js CHANGED
@@ -191,6 +191,11 @@ function buildModelMeta(params) {
191
191
  };
192
192
  if (primaryKey.length > 1) {
193
193
  addCompound(primaryKey.map((field) => field.name), false, model.primaryKey?.clientName);
194
+ } else {
195
+ const only = primaryKey[0];
196
+ if (only !== undefined && !only.isId && !only.isUnique) {
197
+ singleIndexUniques.push({ fields: [only], nullsNotDistinct: false });
198
+ }
194
199
  }
195
200
  for (const index of model.indexes) {
196
201
  if (index.kind !== "unique" || index.where !== undefined)
@@ -7030,4 +7035,4 @@ export {
7030
7035
  COUNT_ALIAS
7031
7036
  };
7032
7037
 
7033
- //# debugId=4B6B11C516D4A81A64756E2164756E21
7038
+ //# debugId=96AA73705B84E72364756E2164756E21