@jskit-ai/database-runtime-mysql 0.1.250 → 0.1.252

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/database-runtime-mysql",
3
- "version": "0.1.250",
3
+ "version": "0.1.252",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -12,7 +12,7 @@
12
12
  "./shared/dialect": "./src/shared/dialect.js"
13
13
  },
14
14
  "dependencies": {
15
- "@jskit-ai/database-runtime": "0.1.252",
15
+ "@jskit-ai/database-runtime": "0.1.254",
16
16
  "mysql2": "^3.11.2"
17
17
  },
18
18
  "jskit": {
@@ -56,6 +56,6 @@
56
56
  }
57
57
  },
58
58
  "peerDependencies": {
59
- "@jskit-ai/kernel": "0.2.3"
59
+ "@jskit-ai/kernel": "0.2.5"
60
60
  }
61
61
  }
@@ -38,7 +38,10 @@ decisions, not framework questions.
38
38
  ## Framework APIs
39
39
 
40
40
  Use `createKnexMigrationConfigFromApp()` from
41
- `@jskit-ai/database-runtime/server/knexMigrationConfig`. The running JSKIT
41
+ `@jskit-ai/database-runtime/server/knexMigrationConfig`, and
42
+ `prepareDatabaseFromApp()` from `@jskit-ai/database-runtime/server/databaseSetup`.
43
+ Both take the dialect and the application's environment
44
+ (`environment: process.env`), which they never read on their own. The running JSKIT
42
45
  application automatically selects the sole installed database driver, while
43
46
  Knex discovers package-owned migrations from the installed dependency graph.
44
47
 
@@ -50,6 +53,14 @@ Knex discovers package-owned migrations from the installed dependency graph.
50
53
  entrypoint for managed sessions and deployments. `example/.env.example` names
51
54
  the connection values and separate test databases without a secret.
52
55
 
56
+ `example/.github/workflows/verify.yml` is a normal app-owned CI workflow with
57
+ exactly one database service: `mariadb` (`mariadb:11.4`, `MARIADB_*`
58
+ variables, port `3306`, a `healthcheck.sh` health check). Copy it whole from
59
+ this pattern and adapt it as source rather than generating it from package
60
+ metadata. Do not combine it with the PostgreSQL pattern's workflow: a MySQL
61
+ application's workflow has no `postgres` service, `POSTGRES_*` variables, port
62
+ `5432`, or `pg_isready` option.
63
+
53
64
  `example/tests/browser/database.js` is the application-owned browser preparation
54
65
  helper. It requires the exact `BROWSER_TEST_DB_NAME`, rejects the ordinary and
55
66
  disposable `TEST_DB_NAME` databases,
@@ -93,10 +104,9 @@ it as `seed` to `prepareDatabaseFromApp()`.
93
104
  foreign-key checks remain enabled, and the normal database is unchanged.
94
105
  Also prove that a new pending migration is applied. Keep this as a regression
95
106
  test when adapting the example; reject a harness that recreates the schema.
96
-
97
- `example/.github/workflows/verify.yml` is a normal app-owned CI workflow with
98
- an explicit MariaDB service. Adapt it as source rather than generating it from
99
- package metadata.
107
+ - Confirm `.github/workflows/verify.yml` parses as YAML and declares only the
108
+ `mariadb` service. GitHub reports an unparseable workflow only as a failed
109
+ run with "no jobs were run".
100
110
 
101
111
  ## Avoid
102
112
 
@@ -104,4 +114,5 @@ package metadata.
104
114
  - generated `.env` secrets
105
115
  - depending on a live schema as the source contract
106
116
  - a second driver installed “just in case”
117
+ - any file, service, port, or variable copied from the PostgreSQL pattern
107
118
  - migration receipts, provenance, replay logs, or generator ownership
@@ -1,11 +1,11 @@
1
1
  import { createKnexMigrationConfigFromApp } from "@jskit-ai/database-runtime/server/knexMigrationConfig";
2
2
 
3
3
  try {
4
- process.loadEnvFile?.(".env");
4
+ process.loadEnvFile(".env");
5
5
  } catch (error) {
6
6
  if (error?.code !== "ENOENT") {
7
7
  throw error;
8
8
  }
9
9
  }
10
10
 
11
- export default await createKnexMigrationConfigFromApp({ client: "mysql2" });
11
+ export default await createKnexMigrationConfigFromApp({ client: "mysql2", environment: process.env });
@@ -8,6 +8,6 @@
8
8
  "db:migrate:status": "knex --knexfile ./knexfile.js migrate:list"
9
9
  },
10
10
  "dependencies": {
11
- "@jskit-ai/database-runtime-mysql": "0.1.250"
11
+ "@jskit-ai/database-runtime-mysql": "0.1.252"
12
12
  }
13
13
  }
@@ -1,3 +1,3 @@
1
1
  import { prepareDatabaseFromApp } from "@jskit-ai/database-runtime/server/databaseSetup";
2
2
 
3
- await prepareDatabaseFromApp({ client: "mysql2" });
3
+ await prepareDatabaseFromApp({ client: "mysql2", environment: process.env });
@@ -1,5 +1,5 @@
1
1
  import { defineProvider } from "@jskit-ai/kernel/shared/capabilities";
2
- import * as mysqlDriver from "../../shared/index.js";
2
+ import { DIALECT_ID, introspectCrudTableSnapshot } from "../../shared/index.js";
3
3
 
4
4
  const MysqlDatabaseDriverProvider = defineProvider({
5
5
  id: "runtime.database.driver.mysql",
@@ -8,7 +8,7 @@ const MysqlDatabaseDriverProvider = defineProvider({
8
8
  },
9
9
  setup() {
10
10
  return {
11
- driver: Object.freeze({ ...mysqlDriver })
11
+ driver: Object.freeze({ DIALECT_ID, introspectCrudTableSnapshot })
12
12
  };
13
13
  }
14
14
  });
@@ -1,7 +1,3 @@
1
1
  const DIALECT_ID = "mysql2";
2
2
 
3
- function getDialectId() {
4
- return DIALECT_ID;
5
- }
6
-
7
- export { DIALECT_ID, getDialectId };
3
+ export { DIALECT_ID };
@@ -1,2 +1,2 @@
1
- export { DIALECT_ID, getDialectId } from "./dialect.js";
1
+ export { DIALECT_ID } from "./dialect.js";
2
2
  export { introspectCrudTableSnapshot } from "./introspectCrudTable.js";
@@ -9,6 +9,7 @@ const TABLE_NAME_PATTERN = /^[A-Za-z0-9_]+$/;
9
9
  const TEMPORAL_DATA_TYPES = new Set(["datetime", "timestamp"]);
10
10
 
11
11
  function requireKnexRaw(knex) {
12
+ // readable-check: allow method-probe - input validation: the application passes its own Knex instance
12
13
  if (!knex || typeof knex.raw !== "function") {
13
14
  throw new TypeError("introspectCrudTableSnapshot requires knex with raw().");
14
15
  }
@@ -28,7 +28,6 @@ test("server provider module exports the declarative mysql driver provider", ()
28
28
 
29
29
  test("shared entrypoint exports mysql dialect helpers", () => {
30
30
  assert.equal(sharedApi.DIALECT_ID, "mysql2");
31
- assert.equal(sharedApi.getDialectId(), "mysql2");
32
31
  assert.equal(typeof sharedApi.introspectCrudTableSnapshot, "function");
33
32
  assert.equal(typeof sharedApi.MysqlDatabaseDriverProvider, "undefined");
34
33
  });
@@ -0,0 +1,42 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import knex from "knex";
4
+ import {
5
+ addMissingForeignKey,
6
+ dropForeignKeyIfPresent,
7
+ hasForeignKey
8
+ } from "@jskit-ai/database-runtime/server/foreignKeyMigrations";
9
+
10
+ const KEY = { tableName: "children", columnName: "parent_id", parentTable: "parents" };
11
+
12
+ test("dropForeignKeyIfPresent drops a MySQL key by the name the database holds", {
13
+ skip: !process.env.TEST_DB_NAME || !process.env.DB_HOST
14
+ }, async () => {
15
+ const environment = process.env;
16
+ const databaseName = `${environment.TEST_DB_NAME}_fk`;
17
+ const connection = { host: environment.DB_HOST, port: Number(environment.DB_PORT), user: environment.DB_USER,
18
+ password: environment.DB_PASSWORD };
19
+ const admin = knex({ client: "mysql2", connection });
20
+ let db = null;
21
+ try {
22
+ await admin.raw("DROP DATABASE IF EXISTS ??", [databaseName]);
23
+ await admin.raw("CREATE DATABASE ??", [databaseName]);
24
+ db = knex({ client: "mysql2", connection: { ...connection, database: databaseName } });
25
+ await db.schema.createTable("parents", (table) => table.increments("id"));
26
+ await db.schema.createTable("children", (table) => {
27
+ table.increments("id");
28
+ table.integer("parent_id").unsigned().nullable();
29
+ table.foreign("parent_id", "children_parent_custom_fk").references("id").inTable("parents");
30
+ });
31
+
32
+ assert.equal(await hasForeignKey(db, KEY), true);
33
+ assert.equal(await addMissingForeignKey(db, KEY), false);
34
+ assert.equal(await dropForeignKeyIfPresent(db, KEY), true);
35
+ assert.equal(await hasForeignKey(db, KEY), false);
36
+ assert.equal(await dropForeignKeyIfPresent(db, KEY), false);
37
+ } finally {
38
+ await db?.destroy();
39
+ await admin.raw("DROP DATABASE IF EXISTS ??", [databaseName]);
40
+ await admin.destroy();
41
+ }
42
+ });
@@ -18,6 +18,5 @@ test("MysqlDatabaseDriverProvider provides the exclusive database driver capabil
18
18
 
19
19
  await runtime.start();
20
20
  assert.equal(driver.DIALECT_ID, "mysql2");
21
- assert.equal(driver.getDialectId(), "mysql2");
22
21
  await runtime.shutdown();
23
22
  });