@hot-updater/postgres 1.1.3 → 1.2.0-rc.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.
- package/dist/index.cjs +18 -0
- package/dist/index.mjs +18 -0
- package/package.json +5 -5
- package/sql/bundles.sql +11 -1
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,22 @@ pg = __toESM(pg, 1);
|
|
|
29
29
|
//#region src/postgres.ts
|
|
30
30
|
const { Pool } = pg.default;
|
|
31
31
|
/**
|
|
32
|
+
* The resource this database reaches, without credentials, under the key
|
|
33
|
+
* `hot-updater doctor` reads to tell the database `hot-updater init` saved
|
|
34
|
+
* from another (a convention CLAUDE.md documents).
|
|
35
|
+
*/
|
|
36
|
+
const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
|
|
37
|
+
/** The server and database a pool reaches: `postgres/<host>:<port>/<database>`. */
|
|
38
|
+
const targetOf = ({ connectionString, host, port, database }) => {
|
|
39
|
+
if (connectionString !== void 0) try {
|
|
40
|
+
const url = new URL(connectionString);
|
|
41
|
+
return `postgres/${url.hostname}:${url.port || "5432"}/${decodeURIComponent(url.pathname.slice(1))}`;
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
return host === void 0 || database === void 0 ? void 0 : `postgres/${host}:${port ?? 5432}/${database}`;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
32
48
|
* Hot Updater's database on PostgreSQL, through a `pg` pool or the given
|
|
33
49
|
* Kysely dialect. Before first use, apply `sql/bundles.sql`, core's tables,
|
|
34
50
|
* and add the tables of the server's plugins with `hot-updater db migrate`;
|
|
@@ -36,12 +52,14 @@ const { Pool } = pg.default;
|
|
|
36
52
|
*/
|
|
37
53
|
const postgres = (config) => {
|
|
38
54
|
const { dialect, ...poolConfig } = config;
|
|
55
|
+
const target = targetOf(poolConfig);
|
|
39
56
|
const db = new kysely.Kysely({ dialect: dialect ?? new kysely.PostgresDialect({ pool: new Pool(poolConfig) }) });
|
|
40
57
|
return {
|
|
41
58
|
...(0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
42
59
|
name: "postgres",
|
|
43
60
|
adapter: (0, _hot_updater_plugin_core.createSqlAdapter)({ executor: (0, _hot_updater_server_adapters_kysely.kyselyExecutor)(db, "postgresql") })
|
|
44
61
|
}),
|
|
62
|
+
...target === void 0 ? {} : { [DATABASE_TARGET]: target },
|
|
45
63
|
dispose: () => db.destroy()
|
|
46
64
|
};
|
|
47
65
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,22 @@ import pg from "pg";
|
|
|
5
5
|
//#region src/postgres.ts
|
|
6
6
|
const { Pool } = pg;
|
|
7
7
|
/**
|
|
8
|
+
* The resource this database reaches, without credentials, under the key
|
|
9
|
+
* `hot-updater doctor` reads to tell the database `hot-updater init` saved
|
|
10
|
+
* from another (a convention CLAUDE.md documents).
|
|
11
|
+
*/
|
|
12
|
+
const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
|
|
13
|
+
/** The server and database a pool reaches: `postgres/<host>:<port>/<database>`. */
|
|
14
|
+
const targetOf = ({ connectionString, host, port, database }) => {
|
|
15
|
+
if (connectionString !== void 0) try {
|
|
16
|
+
const url = new URL(connectionString);
|
|
17
|
+
return `postgres/${url.hostname}:${url.port || "5432"}/${decodeURIComponent(url.pathname.slice(1))}`;
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return host === void 0 || database === void 0 ? void 0 : `postgres/${host}:${port ?? 5432}/${database}`;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
8
24
|
* Hot Updater's database on PostgreSQL, through a `pg` pool or the given
|
|
9
25
|
* Kysely dialect. Before first use, apply `sql/bundles.sql`, core's tables,
|
|
10
26
|
* and add the tables of the server's plugins with `hot-updater db migrate`;
|
|
@@ -12,12 +28,14 @@ const { Pool } = pg;
|
|
|
12
28
|
*/
|
|
13
29
|
const postgres = (config) => {
|
|
14
30
|
const { dialect, ...poolConfig } = config;
|
|
31
|
+
const target = targetOf(poolConfig);
|
|
15
32
|
const db = new Kysely({ dialect: dialect ?? new PostgresDialect({ pool: new Pool(poolConfig) }) });
|
|
16
33
|
return {
|
|
17
34
|
...createEngineDatabase({
|
|
18
35
|
name: "postgres",
|
|
19
36
|
adapter: createSqlAdapter({ executor: kyselyExecutor(db, "postgresql") })
|
|
20
37
|
}),
|
|
38
|
+
...target === void 0 ? {} : { [DATABASE_TARGET]: target },
|
|
21
39
|
dispose: () => db.destroy()
|
|
22
40
|
};
|
|
23
41
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/postgres",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0-rc.0",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"kysely": "0.28.17",
|
|
36
36
|
"pg": "8.13.1",
|
|
37
|
-
"@hot-updater/protocol": "1.
|
|
38
|
-
"@hot-updater/
|
|
39
|
-
"@hot-updater/
|
|
37
|
+
"@hot-updater/protocol": "1.2.0-rc.0",
|
|
38
|
+
"@hot-updater/server": "1.2.0-rc.0",
|
|
39
|
+
"@hot-updater/plugin-core": "1.2.0-rc.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@electric-sql/pglite": "0.4.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"camelcase-keys": "^9.1.3",
|
|
46
46
|
"kysely-pglite-dialect": "1.2.0",
|
|
47
47
|
"pg-minify": "^1.6.5",
|
|
48
|
-
"@hot-updater/test-utils": "1.
|
|
48
|
+
"@hot-updater/test-utils": "1.2.0-rc.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown",
|
package/sql/bundles.sql
CHANGED
|
@@ -34,8 +34,18 @@ CREATE UNIQUE INDEX IF NOT EXISTS "channels_name" ON "channels" ("name");
|
|
|
34
34
|
|
|
35
35
|
CREATE TABLE IF NOT EXISTS "bundle_totals" ("platform_key" varchar(16) COLLATE "C" NOT NULL, "_shard" bigint NOT NULL, "bundles" bigint NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("platform_key", "_shard"));
|
|
36
36
|
|
|
37
|
+
CREATE TABLE IF NOT EXISTS "native_builds" ("id" varchar(36) COLLATE "C" NOT NULL, "scope_key" varchar(2048) COLLATE "C" NOT NULL, "platform" varchar(16) COLLATE "C" NOT NULL, "channel_id" varchar(1408) COLLATE "C" NOT NULL, "fingerprint_hash" varchar(255) COLLATE "C", "app_version" text COLLATE "C", "min_bundle_id" varchar(36) COLLATE "C" NOT NULL, "artifact_kind" varchar(16) COLLATE "C" NOT NULL, "artifact_storage_uri" text COLLATE "C" NOT NULL, "byte_size" bigint NOT NULL, "git_commit_hash" varchar(255) COLLATE "C", "created_at_ms" bigint NOT NULL, "build_key" varchar(69) COLLATE "C", "build_number" varchar(64) COLLATE "C", "submitted_to" varchar(16) COLLATE "C", "submitted_at_ms" bigint, "submitted_version" varchar(255) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
|
|
38
|
+
|
|
39
|
+
CREATE INDEX IF NOT EXISTS "native_builds_byScope" ON "native_builds" ("scope_key", "id");
|
|
40
|
+
|
|
41
|
+
CREATE INDEX IF NOT EXISTS "native_builds_byBuildKey" ON "native_builds" ("scope_key", "build_key", "id");
|
|
42
|
+
|
|
43
|
+
CREATE INDEX IF NOT EXISTS "native_builds_byChannel" ON "native_builds" ("channel_id", "id");
|
|
44
|
+
|
|
45
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "native_builds_min_bundle_id" ON "native_builds" ("min_bundle_id");
|
|
46
|
+
|
|
37
47
|
CREATE TABLE IF NOT EXISTS "private_hot_updater_settings" ("key" varchar(255) COLLATE "C" NOT NULL, "value" varchar(255) COLLATE "C" NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("key"));
|
|
38
48
|
|
|
39
49
|
INSERT INTO "private_hot_updater_settings" ("key", "value", "_v") VALUES ('schema.engine', '1', 0) ON CONFLICT ("key") DO UPDATE SET "value" = excluded."value";
|
|
40
50
|
|
|
41
|
-
INSERT INTO "private_hot_updater_settings" ("key", "value", "_v") VALUES ('schema.core', '1.
|
|
51
|
+
INSERT INTO "private_hot_updater_settings" ("key", "value", "_v") VALUES ('schema.core', '1.2.0', 0) ON CONFLICT ("key") DO UPDATE SET "value" = excluded."value";
|