@hot-updater/plugin-core 1.2.0-rc.50 → 1.2.0-rc.52
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/coreApi.d.cts +32 -1
- package/dist/coreApi.d.mts +32 -1
- package/dist/database/adapter.d.cts +12 -0
- package/dist/database/adapter.d.mts +12 -0
- package/dist/databaseRows.cjs +4 -2
- package/dist/databaseRows.mjs +4 -2
- package/dist/engine/core/schema.cjs +55 -3
- package/dist/engine/core/schema.d.cts +27 -0
- package/dist/engine/core/schema.d.mts +27 -0
- package/dist/engine/core/schema.mjs +55 -4
- package/dist/engine/database/fence.cjs +24 -2
- package/dist/engine/database/fence.d.cts +4 -1
- package/dist/engine/database/fence.d.mts +4 -1
- package/dist/engine/database/fence.mjs +24 -3
- package/dist/engine/database/sql/sqlAdapter.cjs +27 -8
- package/dist/engine/database/sql/sqlAdapter.mjs +28 -9
- package/dist/engine/db/engineMigrator.cjs +32 -9
- package/dist/engine/db/engineMigrator.mjs +33 -10
- package/dist/engine/db/engineSql.cjs +25 -0
- package/dist/engine/db/engineSql.d.cts +13 -1
- package/dist/engine/db/engineSql.d.mts +13 -1
- package/dist/engine/db/engineSql.mjs +26 -2
- package/dist/engine/db/engineSqlMigrator.cjs +12 -6
- package/dist/engine/db/engineSqlMigrator.mjs +13 -7
- package/dist/engine/db/schemaSettings.cjs +22 -2
- package/dist/engine/db/schemaSettings.mjs +23 -4
- package/dist/engine/db/settingsMigrator.cjs +41 -21
- package/dist/engine/db/settingsMigrator.mjs +42 -22
- package/dist/engine/db/sqlSchemaState.cjs +36 -8
- package/dist/engine/db/sqlSchemaState.mjs +36 -9
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/releaseCatalogCompiler.cjs +89 -7
- package/dist/releaseCatalogCompiler.d.cts +12 -1
- package/dist/releaseCatalogCompiler.d.mts +12 -1
- package/dist/releaseCatalogCompiler.mjs +89 -8
- package/dist/releaseCatalogMutation.d.cts +8 -2
- package/dist/releaseCatalogMutation.d.mts +8 -2
- package/dist/types/databaseRows.d.cts +7 -0
- package/dist/types/databaseRows.d.mts +7 -0
- package/package.json +2 -2
package/dist/coreApi.d.cts
CHANGED
|
@@ -202,6 +202,13 @@ interface IosDeviceRequestResult {
|
|
|
202
202
|
/** False when the UDID was already in the registry, whose row is unchanged. */
|
|
203
203
|
readonly created: boolean;
|
|
204
204
|
}
|
|
205
|
+
/** What a release label fill labeled, or with `dryRun` would label. */
|
|
206
|
+
interface ReleaseLabelFill {
|
|
207
|
+
/** Releases that had no label. */
|
|
208
|
+
readonly releases: number;
|
|
209
|
+
/** Catalogs whose releases have labels they lack. */
|
|
210
|
+
readonly catalogs: number;
|
|
211
|
+
}
|
|
205
212
|
interface ReleaseTarget {
|
|
206
213
|
readonly releaseId: string;
|
|
207
214
|
/** Refuses the change when the release is at another revision. */
|
|
@@ -234,6 +241,16 @@ interface HotUpdaterCoreApi {
|
|
|
234
241
|
*/
|
|
235
242
|
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
236
243
|
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
244
|
+
/**
|
|
245
|
+
* The release a label names in a channel and platform, or null: one read
|
|
246
|
+
* of the label's unique index, and one of the release it names, which a
|
|
247
|
+
* key-value store's index copy may outlive.
|
|
248
|
+
*/
|
|
249
|
+
getReleaseByLabel(input: {
|
|
250
|
+
readonly channel: string;
|
|
251
|
+
readonly platform: Platform;
|
|
252
|
+
readonly label: number;
|
|
253
|
+
}): Promise<ReleaseRow | null>;
|
|
237
254
|
listReleases(input: KeysetInput & {
|
|
238
255
|
readonly filter: ReleaseFilter;
|
|
239
256
|
}): Promise<ReleaseRow[]>;
|
|
@@ -332,6 +349,20 @@ interface HotUpdaterCoreApi {
|
|
|
332
349
|
readonly action?: "copy" | "move";
|
|
333
350
|
}): Promise<PromoteReleaseResult>;
|
|
334
351
|
rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
|
|
352
|
+
/**
|
|
353
|
+
* Gives labels to the releases written before labels, or by a server of
|
|
354
|
+
* an earlier release, in the order they were created, per channel and
|
|
355
|
+
* platform; then, unless `catalogs` is false, rebuilds each catalog that
|
|
356
|
+
* differs from its releases only by their labels. With `dryRun`, it writes
|
|
357
|
+
* nothing and counts both. `hot-updater init` and `db migrate` run it.
|
|
358
|
+
* Reads: two per scope with releases and one per channel and platform,
|
|
359
|
+
* then each pending pair's releases, and for the catalog pass what a
|
|
360
|
+
* rebuild preflight reads per catalog.
|
|
361
|
+
*/
|
|
362
|
+
fillReleaseLabels(input?: {
|
|
363
|
+
readonly dryRun?: boolean;
|
|
364
|
+
readonly catalogs?: boolean;
|
|
365
|
+
}): Promise<ReleaseLabelFill>;
|
|
335
366
|
preflightReleaseCatalogRebuild(scopeKey: string): Promise<ReleaseCatalogRebuildPreflight>;
|
|
336
367
|
/** The channel named `name`, created when missing. */
|
|
337
368
|
ensureChannel(name: string): Promise<ChannelRow>;
|
|
@@ -455,4 +486,4 @@ interface HotUpdaterCoreApi {
|
|
|
455
486
|
}): Promise<IosDeviceRow | null>;
|
|
456
487
|
}
|
|
457
488
|
//#endregion
|
|
458
|
-
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, IosDeviceAccount, IosDeviceAccountClaim, IosDeviceOutcome, IosDeviceOutcomeInput, IosDeviceRequestResult, KeysetInput, NativeBuildDistribution, NativeBuildRegistration, NativeBuildSandboxScope, NativeBuildScope, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
|
|
489
|
+
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, IosDeviceAccount, IosDeviceAccountClaim, IosDeviceOutcome, IosDeviceOutcomeInput, IosDeviceRequestResult, KeysetInput, NativeBuildDistribution, NativeBuildRegistration, NativeBuildSandboxScope, NativeBuildScope, ReleaseFilter, ReleaseLabelFill, ReleaseTarget, StoredBundleDeployment };
|
package/dist/coreApi.d.mts
CHANGED
|
@@ -202,6 +202,13 @@ interface IosDeviceRequestResult {
|
|
|
202
202
|
/** False when the UDID was already in the registry, whose row is unchanged. */
|
|
203
203
|
readonly created: boolean;
|
|
204
204
|
}
|
|
205
|
+
/** What a release label fill labeled, or with `dryRun` would label. */
|
|
206
|
+
interface ReleaseLabelFill {
|
|
207
|
+
/** Releases that had no label. */
|
|
208
|
+
readonly releases: number;
|
|
209
|
+
/** Catalogs whose releases have labels they lack. */
|
|
210
|
+
readonly catalogs: number;
|
|
211
|
+
}
|
|
205
212
|
interface ReleaseTarget {
|
|
206
213
|
readonly releaseId: string;
|
|
207
214
|
/** Refuses the change when the release is at another revision. */
|
|
@@ -234,6 +241,16 @@ interface HotUpdaterCoreApi {
|
|
|
234
241
|
*/
|
|
235
242
|
findBaseBundleIds(candidateKey: string, bundleId: string, limit: number): Promise<string[]>;
|
|
236
243
|
getRelease(id: string): Promise<ReleaseRow | null>;
|
|
244
|
+
/**
|
|
245
|
+
* The release a label names in a channel and platform, or null: one read
|
|
246
|
+
* of the label's unique index, and one of the release it names, which a
|
|
247
|
+
* key-value store's index copy may outlive.
|
|
248
|
+
*/
|
|
249
|
+
getReleaseByLabel(input: {
|
|
250
|
+
readonly channel: string;
|
|
251
|
+
readonly platform: Platform;
|
|
252
|
+
readonly label: number;
|
|
253
|
+
}): Promise<ReleaseRow | null>;
|
|
237
254
|
listReleases(input: KeysetInput & {
|
|
238
255
|
readonly filter: ReleaseFilter;
|
|
239
256
|
}): Promise<ReleaseRow[]>;
|
|
@@ -332,6 +349,20 @@ interface HotUpdaterCoreApi {
|
|
|
332
349
|
readonly action?: "copy" | "move";
|
|
333
350
|
}): Promise<PromoteReleaseResult>;
|
|
334
351
|
rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
|
|
352
|
+
/**
|
|
353
|
+
* Gives labels to the releases written before labels, or by a server of
|
|
354
|
+
* an earlier release, in the order they were created, per channel and
|
|
355
|
+
* platform; then, unless `catalogs` is false, rebuilds each catalog that
|
|
356
|
+
* differs from its releases only by their labels. With `dryRun`, it writes
|
|
357
|
+
* nothing and counts both. `hot-updater init` and `db migrate` run it.
|
|
358
|
+
* Reads: two per scope with releases and one per channel and platform,
|
|
359
|
+
* then each pending pair's releases, and for the catalog pass what a
|
|
360
|
+
* rebuild preflight reads per catalog.
|
|
361
|
+
*/
|
|
362
|
+
fillReleaseLabels(input?: {
|
|
363
|
+
readonly dryRun?: boolean;
|
|
364
|
+
readonly catalogs?: boolean;
|
|
365
|
+
}): Promise<ReleaseLabelFill>;
|
|
335
366
|
preflightReleaseCatalogRebuild(scopeKey: string): Promise<ReleaseCatalogRebuildPreflight>;
|
|
336
367
|
/** The channel named `name`, created when missing. */
|
|
337
368
|
ensureChannel(name: string): Promise<ChannelRow>;
|
|
@@ -455,4 +486,4 @@ interface HotUpdaterCoreApi {
|
|
|
455
486
|
}): Promise<IosDeviceRow | null>;
|
|
456
487
|
}
|
|
457
488
|
//#endregion
|
|
458
|
-
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, IosDeviceAccount, IosDeviceAccountClaim, IosDeviceOutcome, IosDeviceOutcomeInput, IosDeviceRequestResult, KeysetInput, NativeBuildDistribution, NativeBuildRegistration, NativeBuildSandboxScope, NativeBuildScope, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
|
|
489
|
+
export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, IosDeviceAccount, IosDeviceAccountClaim, IosDeviceOutcome, IosDeviceOutcomeInput, IosDeviceRequestResult, KeysetInput, NativeBuildDistribution, NativeBuildRegistration, NativeBuildSandboxScope, NativeBuildScope, ReleaseFilter, ReleaseLabelFill, ReleaseTarget, StoredBundleDeployment };
|
|
@@ -168,6 +168,18 @@ interface DatabaseAdapter {
|
|
|
168
168
|
fillIndex?(table: PhysicalTable, index: string, options?: {
|
|
169
169
|
readonly dryRun?: boolean;
|
|
170
170
|
}): Promise<number>;
|
|
171
|
+
/**
|
|
172
|
+
* For a store whose tables have columns: adds those of `columns` that
|
|
173
|
+
* `table` lacks, nullable, or with `dryRun` only finds them, and returns
|
|
174
|
+
* them; none for a table that doesn't exist yet. Migrations call it, before
|
|
175
|
+
* `apply` creates the indexes on them, for a column declared on a table a
|
|
176
|
+
* released schema created, such as core's `releases.label`. A store whose
|
|
177
|
+
* rows hold any field, such as a key-value store or MongoDB, leaves it
|
|
178
|
+
* out.
|
|
179
|
+
*/
|
|
180
|
+
addColumns?(table: PhysicalTable, columns: readonly string[], options?: {
|
|
181
|
+
readonly dryRun?: boolean;
|
|
182
|
+
}): Promise<string[]>;
|
|
171
183
|
};
|
|
172
184
|
dispose?(): Promise<void>;
|
|
173
185
|
}
|
|
@@ -168,6 +168,18 @@ interface DatabaseAdapter {
|
|
|
168
168
|
fillIndex?(table: PhysicalTable, index: string, options?: {
|
|
169
169
|
readonly dryRun?: boolean;
|
|
170
170
|
}): Promise<number>;
|
|
171
|
+
/**
|
|
172
|
+
* For a store whose tables have columns: adds those of `columns` that
|
|
173
|
+
* `table` lacks, nullable, or with `dryRun` only finds them, and returns
|
|
174
|
+
* them; none for a table that doesn't exist yet. Migrations call it, before
|
|
175
|
+
* `apply` creates the indexes on them, for a column declared on a table a
|
|
176
|
+
* released schema created, such as core's `releases.label`. A store whose
|
|
177
|
+
* rows hold any field, such as a key-value store or MongoDB, leaves it
|
|
178
|
+
* out.
|
|
179
|
+
*/
|
|
180
|
+
addColumns?(table: PhysicalTable, columns: readonly string[], options?: {
|
|
181
|
+
readonly dryRun?: boolean;
|
|
182
|
+
}): Promise<string[]>;
|
|
171
183
|
};
|
|
172
184
|
dispose?(): Promise<void>;
|
|
173
185
|
}
|
package/dist/databaseRows.cjs
CHANGED
|
@@ -20,7 +20,8 @@ const releaseToRow = (release, scopeKey) => ({
|
|
|
20
20
|
operation: release.operation,
|
|
21
21
|
source_release_id: release.sourceReleaseId,
|
|
22
22
|
created_at_ms: release.createdAtMs,
|
|
23
|
-
updated_at_ms: release.updatedAtMs
|
|
23
|
+
updated_at_ms: release.updatedAtMs,
|
|
24
|
+
label: release.label ?? null
|
|
24
25
|
});
|
|
25
26
|
const releaseRowToRelease = (row) => ({
|
|
26
27
|
id: row.id,
|
|
@@ -40,7 +41,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
40
41
|
operation: row.operation,
|
|
41
42
|
sourceReleaseId: row.source_release_id,
|
|
42
43
|
createdAtMs: row.created_at_ms,
|
|
43
|
-
updatedAtMs: row.updated_at_ms
|
|
44
|
+
updatedAtMs: row.updated_at_ms,
|
|
45
|
+
label: row.label ?? null
|
|
44
46
|
});
|
|
45
47
|
const BundleRowHydrationErrorReason = {
|
|
46
48
|
duplicatePatchId: "duplicate_patch_id",
|
package/dist/databaseRows.mjs
CHANGED
|
@@ -20,7 +20,8 @@ const releaseToRow = (release, scopeKey) => ({
|
|
|
20
20
|
operation: release.operation,
|
|
21
21
|
source_release_id: release.sourceReleaseId,
|
|
22
22
|
created_at_ms: release.createdAtMs,
|
|
23
|
-
updated_at_ms: release.updatedAtMs
|
|
23
|
+
updated_at_ms: release.updatedAtMs,
|
|
24
|
+
label: release.label ?? null
|
|
24
25
|
});
|
|
25
26
|
const releaseRowToRelease = (row) => ({
|
|
26
27
|
id: row.id,
|
|
@@ -40,7 +41,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
40
41
|
operation: row.operation,
|
|
41
42
|
sourceReleaseId: row.source_release_id,
|
|
42
43
|
createdAtMs: row.created_at_ms,
|
|
43
|
-
updatedAtMs: row.updated_at_ms
|
|
44
|
+
updatedAtMs: row.updated_at_ms,
|
|
45
|
+
label: row.label ?? null
|
|
44
46
|
});
|
|
45
47
|
const BundleRowHydrationErrorReason = {
|
|
46
48
|
duplicatePatchId: "duplicate_patch_id",
|
|
@@ -16,7 +16,7 @@ const CHANNEL_ID = {
|
|
|
16
16
|
* every database's migrator creates missing tables and then records the
|
|
17
17
|
* version, and none of them changes an existing table's columns, so changing
|
|
18
18
|
* one needs a migration step of its own first. An index added to an existing
|
|
19
|
-
* table is listed in `LATE_INDEXES`. The schema fence answers 503 on
|
|
19
|
+
* table is listed in `LATE_INDEXES`, and a column in `LATE_COLUMNS`. The schema fence answers 503 on
|
|
20
20
|
* a database whose row differs, until it runs. Before a version is released,
|
|
21
21
|
* its tables change in place in its own migration, and a database one of its
|
|
22
22
|
* prereleases migrated takes the same change by hand: the fence compares this
|
|
@@ -169,7 +169,11 @@ const releases = require_schema.defineTable({
|
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
171
|
created_at_ms: { type: "integer" },
|
|
172
|
-
updated_at_ms: { type: "integer" }
|
|
172
|
+
updated_at_ms: { type: "integer" },
|
|
173
|
+
label: {
|
|
174
|
+
type: "integer",
|
|
175
|
+
required: false
|
|
176
|
+
}
|
|
173
177
|
}, {
|
|
174
178
|
key: ["id"],
|
|
175
179
|
indexes: {
|
|
@@ -206,6 +210,15 @@ const releases = require_schema.defineTable({
|
|
|
206
210
|
scopes: {
|
|
207
211
|
eq: [],
|
|
208
212
|
sort: ["scope_key"]
|
|
213
|
+
},
|
|
214
|
+
byLabel: {
|
|
215
|
+
eq: [
|
|
216
|
+
"channel_id",
|
|
217
|
+
"platform",
|
|
218
|
+
"label"
|
|
219
|
+
],
|
|
220
|
+
sort: [],
|
|
221
|
+
unique: true
|
|
209
222
|
}
|
|
210
223
|
}
|
|
211
224
|
});
|
|
@@ -222,6 +235,43 @@ const LATE_INDEXES = [{
|
|
|
222
235
|
table: "releases",
|
|
223
236
|
index: "scopes"
|
|
224
237
|
}];
|
|
238
|
+
/**
|
|
239
|
+
* Columns added to a table that a released schema created: a migrator whose
|
|
240
|
+
* store has columns adds each one missing from an existing table, with
|
|
241
|
+
* `ALTER TABLE … ADD COLUMN`, before it creates the table's indexes, and
|
|
242
|
+
* `db migrate` on a database whose settings match still looks for them,
|
|
243
|
+
* since a database a prerelease migrated records the same settings. Each
|
|
244
|
+
* is optional, so rows written before it, and rows a server of the earlier
|
|
245
|
+
* release still writes, read as null. `releases.label` arrived in 1.2.0.
|
|
246
|
+
*/
|
|
247
|
+
const LATE_COLUMNS = [{
|
|
248
|
+
table: "releases",
|
|
249
|
+
column: "label"
|
|
250
|
+
}];
|
|
251
|
+
/**
|
|
252
|
+
* One counter per sequence: `releases/<platform>/<channel ID>` holds the
|
|
253
|
+
* last label that channel and platform's releases took. A deploy or a
|
|
254
|
+
* promote reads it and writes the next value in the transaction that writes
|
|
255
|
+
* the release, so two writers never take one label. `is_filled` is true once
|
|
256
|
+
* every release of the sequence written before labels has one, in ID order;
|
|
257
|
+
* until then a writer fills them first. Deleting a channel deletes its
|
|
258
|
+
* counters, so a channel created again with the name starts at 1.
|
|
259
|
+
*/
|
|
260
|
+
const labelSequences = require_schema.defineTable({
|
|
261
|
+
id: {
|
|
262
|
+
type: "string",
|
|
263
|
+
maxLength: 1440,
|
|
264
|
+
ascii: true
|
|
265
|
+
},
|
|
266
|
+
last_label: { type: "integer" },
|
|
267
|
+
is_filled: { type: "boolean" }
|
|
268
|
+
}, {
|
|
269
|
+
key: ["id"],
|
|
270
|
+
indexes: { all: {
|
|
271
|
+
eq: [],
|
|
272
|
+
sort: ["id"]
|
|
273
|
+
} }
|
|
274
|
+
});
|
|
225
275
|
/** One compiled catalog per scope; the update check reads exactly this row. */
|
|
226
276
|
const releaseCatalogs = require_schema.defineTable({
|
|
227
277
|
scope_key: {
|
|
@@ -590,7 +640,8 @@ const coreSchema = {
|
|
|
590
640
|
}),
|
|
591
641
|
native_builds: nativeBuilds,
|
|
592
642
|
ios_devices: iosDevices,
|
|
593
|
-
ios_device_account: iosDeviceAccount
|
|
643
|
+
ios_device_account: iosDeviceAccount,
|
|
644
|
+
label_sequences: labelSequences
|
|
594
645
|
};
|
|
595
646
|
/** Core's module: always installed, never a plugin. */
|
|
596
647
|
const coreModule = {
|
|
@@ -599,6 +650,7 @@ const coreModule = {
|
|
|
599
650
|
};
|
|
600
651
|
//#endregion
|
|
601
652
|
exports.HOT_UPDATER_SCHEMA_VERSION = HOT_UPDATER_SCHEMA_VERSION;
|
|
653
|
+
exports.LATE_COLUMNS = LATE_COLUMNS;
|
|
602
654
|
exports.LATE_INDEXES = LATE_INDEXES;
|
|
603
655
|
exports.coreModule = coreModule;
|
|
604
656
|
exports.coreSchema = coreSchema;
|
|
@@ -179,6 +179,10 @@ declare const coreSchema: {
|
|
|
179
179
|
readonly updated_at_ms: {
|
|
180
180
|
readonly type: "integer";
|
|
181
181
|
};
|
|
182
|
+
readonly label: {
|
|
183
|
+
readonly type: "integer";
|
|
184
|
+
readonly required: false;
|
|
185
|
+
};
|
|
182
186
|
}, {}, {
|
|
183
187
|
readonly byScope: {
|
|
184
188
|
readonly eq: readonly ["scope_key"];
|
|
@@ -214,6 +218,11 @@ declare const coreSchema: {
|
|
|
214
218
|
readonly eq: readonly [];
|
|
215
219
|
readonly sort: readonly ["scope_key"];
|
|
216
220
|
};
|
|
221
|
+
readonly byLabel: {
|
|
222
|
+
readonly eq: readonly ["channel_id", "platform", "label"];
|
|
223
|
+
readonly sort: readonly [];
|
|
224
|
+
readonly unique: true;
|
|
225
|
+
};
|
|
217
226
|
}, readonly ["id"]>;
|
|
218
227
|
readonly release_catalogs: TableDefinition<{
|
|
219
228
|
readonly scope_key: {
|
|
@@ -532,6 +541,24 @@ declare const coreSchema: {
|
|
|
532
541
|
readonly sort: readonly ["id"];
|
|
533
542
|
};
|
|
534
543
|
}, readonly ["id"]>;
|
|
544
|
+
readonly label_sequences: TableDefinition<{
|
|
545
|
+
readonly id: {
|
|
546
|
+
readonly type: "string";
|
|
547
|
+
readonly maxLength: 1440;
|
|
548
|
+
readonly ascii: true;
|
|
549
|
+
};
|
|
550
|
+
readonly last_label: {
|
|
551
|
+
readonly type: "integer";
|
|
552
|
+
};
|
|
553
|
+
readonly is_filled: {
|
|
554
|
+
readonly type: "boolean";
|
|
555
|
+
};
|
|
556
|
+
}, {}, {
|
|
557
|
+
readonly all: {
|
|
558
|
+
readonly eq: readonly [];
|
|
559
|
+
readonly sort: readonly ["id"];
|
|
560
|
+
};
|
|
561
|
+
}, readonly ["id"]>;
|
|
535
562
|
};
|
|
536
563
|
/**
|
|
537
564
|
* Core's tables as the engine types them: the type of `createEngine`'s
|
|
@@ -179,6 +179,10 @@ declare const coreSchema: {
|
|
|
179
179
|
readonly updated_at_ms: {
|
|
180
180
|
readonly type: "integer";
|
|
181
181
|
};
|
|
182
|
+
readonly label: {
|
|
183
|
+
readonly type: "integer";
|
|
184
|
+
readonly required: false;
|
|
185
|
+
};
|
|
182
186
|
}, {}, {
|
|
183
187
|
readonly byScope: {
|
|
184
188
|
readonly eq: readonly ["scope_key"];
|
|
@@ -214,6 +218,11 @@ declare const coreSchema: {
|
|
|
214
218
|
readonly eq: readonly [];
|
|
215
219
|
readonly sort: readonly ["scope_key"];
|
|
216
220
|
};
|
|
221
|
+
readonly byLabel: {
|
|
222
|
+
readonly eq: readonly ["channel_id", "platform", "label"];
|
|
223
|
+
readonly sort: readonly [];
|
|
224
|
+
readonly unique: true;
|
|
225
|
+
};
|
|
217
226
|
}, readonly ["id"]>;
|
|
218
227
|
readonly release_catalogs: TableDefinition<{
|
|
219
228
|
readonly scope_key: {
|
|
@@ -532,6 +541,24 @@ declare const coreSchema: {
|
|
|
532
541
|
readonly sort: readonly ["id"];
|
|
533
542
|
};
|
|
534
543
|
}, readonly ["id"]>;
|
|
544
|
+
readonly label_sequences: TableDefinition<{
|
|
545
|
+
readonly id: {
|
|
546
|
+
readonly type: "string";
|
|
547
|
+
readonly maxLength: 1440;
|
|
548
|
+
readonly ascii: true;
|
|
549
|
+
};
|
|
550
|
+
readonly last_label: {
|
|
551
|
+
readonly type: "integer";
|
|
552
|
+
};
|
|
553
|
+
readonly is_filled: {
|
|
554
|
+
readonly type: "boolean";
|
|
555
|
+
};
|
|
556
|
+
}, {}, {
|
|
557
|
+
readonly all: {
|
|
558
|
+
readonly eq: readonly [];
|
|
559
|
+
readonly sort: readonly ["id"];
|
|
560
|
+
};
|
|
561
|
+
}, readonly ["id"]>;
|
|
535
562
|
};
|
|
536
563
|
/**
|
|
537
564
|
* Core's tables as the engine types them: the type of `createEngine`'s
|
|
@@ -16,7 +16,7 @@ const CHANNEL_ID = {
|
|
|
16
16
|
* every database's migrator creates missing tables and then records the
|
|
17
17
|
* version, and none of them changes an existing table's columns, so changing
|
|
18
18
|
* one needs a migration step of its own first. An index added to an existing
|
|
19
|
-
* table is listed in `LATE_INDEXES`. The schema fence answers 503 on
|
|
19
|
+
* table is listed in `LATE_INDEXES`, and a column in `LATE_COLUMNS`. The schema fence answers 503 on
|
|
20
20
|
* a database whose row differs, until it runs. Before a version is released,
|
|
21
21
|
* its tables change in place in its own migration, and a database one of its
|
|
22
22
|
* prereleases migrated takes the same change by hand: the fence compares this
|
|
@@ -169,7 +169,11 @@ const releases = defineTable({
|
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
171
|
created_at_ms: { type: "integer" },
|
|
172
|
-
updated_at_ms: { type: "integer" }
|
|
172
|
+
updated_at_ms: { type: "integer" },
|
|
173
|
+
label: {
|
|
174
|
+
type: "integer",
|
|
175
|
+
required: false
|
|
176
|
+
}
|
|
173
177
|
}, {
|
|
174
178
|
key: ["id"],
|
|
175
179
|
indexes: {
|
|
@@ -206,6 +210,15 @@ const releases = defineTable({
|
|
|
206
210
|
scopes: {
|
|
207
211
|
eq: [],
|
|
208
212
|
sort: ["scope_key"]
|
|
213
|
+
},
|
|
214
|
+
byLabel: {
|
|
215
|
+
eq: [
|
|
216
|
+
"channel_id",
|
|
217
|
+
"platform",
|
|
218
|
+
"label"
|
|
219
|
+
],
|
|
220
|
+
sort: [],
|
|
221
|
+
unique: true
|
|
209
222
|
}
|
|
210
223
|
}
|
|
211
224
|
});
|
|
@@ -222,6 +235,43 @@ const LATE_INDEXES = [{
|
|
|
222
235
|
table: "releases",
|
|
223
236
|
index: "scopes"
|
|
224
237
|
}];
|
|
238
|
+
/**
|
|
239
|
+
* Columns added to a table that a released schema created: a migrator whose
|
|
240
|
+
* store has columns adds each one missing from an existing table, with
|
|
241
|
+
* `ALTER TABLE … ADD COLUMN`, before it creates the table's indexes, and
|
|
242
|
+
* `db migrate` on a database whose settings match still looks for them,
|
|
243
|
+
* since a database a prerelease migrated records the same settings. Each
|
|
244
|
+
* is optional, so rows written before it, and rows a server of the earlier
|
|
245
|
+
* release still writes, read as null. `releases.label` arrived in 1.2.0.
|
|
246
|
+
*/
|
|
247
|
+
const LATE_COLUMNS = [{
|
|
248
|
+
table: "releases",
|
|
249
|
+
column: "label"
|
|
250
|
+
}];
|
|
251
|
+
/**
|
|
252
|
+
* One counter per sequence: `releases/<platform>/<channel ID>` holds the
|
|
253
|
+
* last label that channel and platform's releases took. A deploy or a
|
|
254
|
+
* promote reads it and writes the next value in the transaction that writes
|
|
255
|
+
* the release, so two writers never take one label. `is_filled` is true once
|
|
256
|
+
* every release of the sequence written before labels has one, in ID order;
|
|
257
|
+
* until then a writer fills them first. Deleting a channel deletes its
|
|
258
|
+
* counters, so a channel created again with the name starts at 1.
|
|
259
|
+
*/
|
|
260
|
+
const labelSequences = defineTable({
|
|
261
|
+
id: {
|
|
262
|
+
type: "string",
|
|
263
|
+
maxLength: 1440,
|
|
264
|
+
ascii: true
|
|
265
|
+
},
|
|
266
|
+
last_label: { type: "integer" },
|
|
267
|
+
is_filled: { type: "boolean" }
|
|
268
|
+
}, {
|
|
269
|
+
key: ["id"],
|
|
270
|
+
indexes: { all: {
|
|
271
|
+
eq: [],
|
|
272
|
+
sort: ["id"]
|
|
273
|
+
} }
|
|
274
|
+
});
|
|
225
275
|
/** One compiled catalog per scope; the update check reads exactly this row. */
|
|
226
276
|
const releaseCatalogs = defineTable({
|
|
227
277
|
scope_key: {
|
|
@@ -590,7 +640,8 @@ const coreSchema = {
|
|
|
590
640
|
}),
|
|
591
641
|
native_builds: nativeBuilds,
|
|
592
642
|
ios_devices: iosDevices,
|
|
593
|
-
ios_device_account: iosDeviceAccount
|
|
643
|
+
ios_device_account: iosDeviceAccount,
|
|
644
|
+
label_sequences: labelSequences
|
|
594
645
|
};
|
|
595
646
|
/** Core's module: always installed, never a plugin. */
|
|
596
647
|
const coreModule = {
|
|
@@ -598,4 +649,4 @@ const coreModule = {
|
|
|
598
649
|
schema: coreSchema
|
|
599
650
|
};
|
|
600
651
|
//#endregion
|
|
601
|
-
export { HOT_UPDATER_SCHEMA_VERSION, LATE_INDEXES, coreModule, coreSchema };
|
|
652
|
+
export { HOT_UPDATER_SCHEMA_VERSION, LATE_COLUMNS, LATE_INDEXES, coreModule, coreSchema };
|
|
@@ -33,6 +33,23 @@ const SETTINGS_TABLE = {
|
|
|
33
33
|
/** The engine's storage-layout generation; it changes only with a migration. */
|
|
34
34
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
35
35
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
36
|
+
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
37
|
+
const compareVersions = (left, right) => {
|
|
38
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
39
|
+
const [a, b] = [parse(left), parse(right)];
|
|
40
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
41
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
42
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
43
|
+
if (difference !== 0) return difference;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The `schema.core` a newer release recorded, which `hot-updater db migrate`
|
|
49
|
+
* never moves back: the fix is to upgrade, not to migrate.
|
|
50
|
+
*/
|
|
51
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
52
|
+
const newerMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is "${found}"; expected "${expected}". The database was migrated by Hot Updater ${found}: upgrade hot-updater and the @hot-updater packages to ${found} or later.`;
|
|
36
53
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
37
54
|
/**
|
|
38
55
|
* How to migrate a database the fence refused: doctor names the command for
|
|
@@ -46,7 +63,10 @@ const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engin
|
|
|
46
63
|
const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
47
64
|
const settingsMessage = (adapterName, settings) => `Hot Updater schema settings for ${adapterName} are not migrated: ${settings.map(stored).join(", and ")}. ${MIGRATE_SCHEMA_FIX}`;
|
|
48
65
|
const pluginsMessage = (adapterName, plugins, settings, fix) => `The tables of ${plugins.length === 1 ? "plugin" : "plugins"} ${listed(plugins.map((id) => `"${id}"`))} are not migrated on ${adapterName}: schema ${settings.length === 1 ? "setting" : "settings"} ${settings.map(stored).join(", and ")}. ${fix}`;
|
|
49
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
68
|
+
* Hot Updater; the handler answers 503.
|
|
69
|
+
*/
|
|
50
70
|
var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
51
71
|
adapterName;
|
|
52
72
|
currentVersion;
|
|
@@ -61,7 +81,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
61
81
|
constructor(adapterName, currentVersion, setting, options) {
|
|
62
82
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
63
83
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
64
|
-
|
|
84
|
+
const newer = newerCore(settings);
|
|
85
|
+
super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
65
86
|
this.adapterName = adapterName;
|
|
66
87
|
this.currentVersion = currentVersion;
|
|
67
88
|
this.setting = setting;
|
|
@@ -176,6 +197,7 @@ exports.ENGINE_SCHEMA_KEY = ENGINE_SCHEMA_KEY;
|
|
|
176
197
|
exports.HotUpdaterSchemaMigrationRequiredError = HotUpdaterSchemaMigrationRequiredError;
|
|
177
198
|
exports.SETTINGS_TABLE = SETTINGS_TABLE;
|
|
178
199
|
exports.checkSchemaFence = checkSchemaFence;
|
|
200
|
+
exports.compareVersions = compareVersions;
|
|
179
201
|
exports.fencedName = fencedName;
|
|
180
202
|
exports.isMissingSchemaError = isMissingSchemaError;
|
|
181
203
|
exports.readSettings = readSettings;
|
|
@@ -13,7 +13,10 @@ interface SchemaSettingMismatch {
|
|
|
13
13
|
readonly expected: string;
|
|
14
14
|
readonly found: string | null;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
18
|
+
* Hot Updater; the handler answers 503.
|
|
19
|
+
*/
|
|
17
20
|
declare class HotUpdaterSchemaMigrationRequiredError extends Error {
|
|
18
21
|
readonly adapterName: string;
|
|
19
22
|
readonly currentVersion: string | undefined;
|
|
@@ -13,7 +13,10 @@ interface SchemaSettingMismatch {
|
|
|
13
13
|
readonly expected: string;
|
|
14
14
|
readonly found: string | null;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
18
|
+
* Hot Updater; the handler answers 503.
|
|
19
|
+
*/
|
|
17
20
|
declare class HotUpdaterSchemaMigrationRequiredError extends Error {
|
|
18
21
|
readonly adapterName: string;
|
|
19
22
|
readonly currentVersion: string | undefined;
|
|
@@ -33,6 +33,23 @@ const SETTINGS_TABLE = {
|
|
|
33
33
|
/** The engine's storage-layout generation; it changes only with a migration. */
|
|
34
34
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
35
35
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
36
|
+
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
37
|
+
const compareVersions = (left, right) => {
|
|
38
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
39
|
+
const [a, b] = [parse(left), parse(right)];
|
|
40
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
41
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
42
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
43
|
+
if (difference !== 0) return difference;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The `schema.core` a newer release recorded, which `hot-updater db migrate`
|
|
49
|
+
* never moves back: the fix is to upgrade, not to migrate.
|
|
50
|
+
*/
|
|
51
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
52
|
+
const newerMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is "${found}"; expected "${expected}". The database was migrated by Hot Updater ${found}: upgrade hot-updater and the @hot-updater packages to ${found} or later.`;
|
|
36
53
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
37
54
|
/**
|
|
38
55
|
* How to migrate a database the fence refused: doctor names the command for
|
|
@@ -46,7 +63,10 @@ const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engin
|
|
|
46
63
|
const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
47
64
|
const settingsMessage = (adapterName, settings) => `Hot Updater schema settings for ${adapterName} are not migrated: ${settings.map(stored).join(", and ")}. ${MIGRATE_SCHEMA_FIX}`;
|
|
48
65
|
const pluginsMessage = (adapterName, plugins, settings, fix) => `The tables of ${plugins.length === 1 ? "plugin" : "plugins"} ${listed(plugins.map((id) => `"${id}"`))} are not migrated on ${adapterName}: schema ${settings.length === 1 ? "setting" : "settings"} ${settings.map(stored).join(", and ")}. ${fix}`;
|
|
49
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
68
|
+
* Hot Updater; the handler answers 503.
|
|
69
|
+
*/
|
|
50
70
|
var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
51
71
|
adapterName;
|
|
52
72
|
currentVersion;
|
|
@@ -61,7 +81,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
61
81
|
constructor(adapterName, currentVersion, setting, options) {
|
|
62
82
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
63
83
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
64
|
-
|
|
84
|
+
const newer = newerCore(settings);
|
|
85
|
+
super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
65
86
|
this.adapterName = adapterName;
|
|
66
87
|
this.currentVersion = currentVersion;
|
|
67
88
|
this.setting = setting;
|
|
@@ -172,4 +193,4 @@ const withSchemaFence = (adapter, adapterName, expected, fix) => {
|
|
|
172
193
|
};
|
|
173
194
|
};
|
|
174
195
|
//#endregion
|
|
175
|
-
export { ENGINE_SCHEMA_KEY, HotUpdaterSchemaMigrationRequiredError, SETTINGS_TABLE, checkSchemaFence, fencedName, isMissingSchemaError, readSettings, withSchemaFence };
|
|
196
|
+
export { ENGINE_SCHEMA_KEY, HotUpdaterSchemaMigrationRequiredError, SETTINGS_TABLE, checkSchemaFence, compareVersions, fencedName, isMissingSchemaError, readSettings, withSchemaFence };
|