@hot-updater/plugin-core 1.2.0-rc.50 → 1.2.0-rc.51
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/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 +40 -9
- package/dist/engine/db/settingsMigrator.mjs +41 -10
- package/dist/engine/db/sqlSchemaState.cjs +36 -8
- package/dist/engine/db/sqlSchemaState.mjs +36 -9
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/releaseCatalogCompiler.cjs +18 -7
- package/dist/releaseCatalogCompiler.mjs +18 -7
- package/dist/releaseCatalogMutation.d.cts +6 -0
- package/dist/releaseCatalogMutation.d.mts +6 -0
- 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 };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_adapter = require("../../../database/adapter.cjs");
|
|
2
2
|
const require_values = require("../../../database/values.cjs");
|
|
3
3
|
const require_sqlSchema = require("./sqlSchema.cjs");
|
|
4
|
+
const require_sqlSchemaState = require("../../db/sqlSchemaState.cjs");
|
|
4
5
|
//#region src/engine/database/sql/sqlAdapter.ts
|
|
5
6
|
/** Where a batch write records its first failed op, before any change applies. */
|
|
6
7
|
const WRITE_GUARD_TABLE = {
|
|
@@ -279,14 +280,32 @@ const createSqlAdapter = ({ executor, tablePrefix = "", maxOps = 1e3, maxParams
|
|
|
279
280
|
return done;
|
|
280
281
|
})).at(-1)?.changes ?? 0;
|
|
281
282
|
},
|
|
282
|
-
migrations: {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
283
|
+
migrations: {
|
|
284
|
+
async apply(tables) {
|
|
285
|
+
const created = executor.batch && !tables.includes(WRITE_GUARD_TABLE) ? [...tables, WRITE_GUARD_TABLE] : tables;
|
|
286
|
+
const statements = require_sqlSchema.createTableStatements(dialect, created, tablePrefix);
|
|
287
|
+
for (const text of statements) await executor.execute({
|
|
288
|
+
sql: text,
|
|
289
|
+
params: []
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
async addColumns(table, columns, { dryRun = false } = {}) {
|
|
293
|
+
const [shape] = require_sqlSchema.sqlTableShapes(dialect, [table], tablePrefix);
|
|
294
|
+
const state = await require_sqlSchemaState.readSqlSchemaState(executor);
|
|
295
|
+
if (shape === void 0 || !state.hasTable(shape.name)) return [];
|
|
296
|
+
const missing = columns.filter((column) => !state.hasColumn(shape.name, column));
|
|
297
|
+
if (dryRun) return missing;
|
|
298
|
+
for (const name of missing) {
|
|
299
|
+
const column = shape.columns.find((candidate) => candidate.name === name);
|
|
300
|
+
if (column === void 0 || column.notNull) throw new Error(`${table.name}.${name} can't be added to an existing table: only an optional column can.`);
|
|
301
|
+
await executor.execute({
|
|
302
|
+
sql: `ALTER TABLE ${require_sqlSchema.quoteSql(dialect, shape.name)} ADD COLUMN ${require_sqlSchema.quoteSql(dialect, name)} ${column.type}`,
|
|
303
|
+
params: []
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return missing;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
290
309
|
};
|
|
291
310
|
};
|
|
292
311
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { findPhysicalColumn, findPhysicalIndex, indexOrderColumns, rowKey } from "../../../database/adapter.mjs";
|
|
2
2
|
import { indexEntries, indexOrderTuple, normalizeStoredRow } from "../../../database/values.mjs";
|
|
3
|
-
import { createTableStatements, isMultiIndex, pruneStatements, quoteSql } from "./sqlSchema.mjs";
|
|
3
|
+
import { createTableStatements, isMultiIndex, pruneStatements, quoteSql, sqlTableShapes } from "./sqlSchema.mjs";
|
|
4
|
+
import { readSqlSchemaState } from "../../db/sqlSchemaState.mjs";
|
|
4
5
|
//#region src/engine/database/sql/sqlAdapter.ts
|
|
5
6
|
/** Where a batch write records its first failed op, before any change applies. */
|
|
6
7
|
const WRITE_GUARD_TABLE = {
|
|
@@ -279,14 +280,32 @@ const createSqlAdapter = ({ executor, tablePrefix = "", maxOps = 1e3, maxParams
|
|
|
279
280
|
return done;
|
|
280
281
|
})).at(-1)?.changes ?? 0;
|
|
281
282
|
},
|
|
282
|
-
migrations: {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
283
|
+
migrations: {
|
|
284
|
+
async apply(tables) {
|
|
285
|
+
const created = executor.batch && !tables.includes(WRITE_GUARD_TABLE) ? [...tables, WRITE_GUARD_TABLE] : tables;
|
|
286
|
+
const statements = createTableStatements(dialect, created, tablePrefix);
|
|
287
|
+
for (const text of statements) await executor.execute({
|
|
288
|
+
sql: text,
|
|
289
|
+
params: []
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
async addColumns(table, columns, { dryRun = false } = {}) {
|
|
293
|
+
const [shape] = sqlTableShapes(dialect, [table], tablePrefix);
|
|
294
|
+
const state = await readSqlSchemaState(executor);
|
|
295
|
+
if (shape === void 0 || !state.hasTable(shape.name)) return [];
|
|
296
|
+
const missing = columns.filter((column) => !state.hasColumn(shape.name, column));
|
|
297
|
+
if (dryRun) return missing;
|
|
298
|
+
for (const name of missing) {
|
|
299
|
+
const column = shape.columns.find((candidate) => candidate.name === name);
|
|
300
|
+
if (column === void 0 || column.notNull) throw new Error(`${table.name}.${name} can't be added to an existing table: only an optional column can.`);
|
|
301
|
+
await executor.execute({
|
|
302
|
+
sql: `ALTER TABLE ${quoteSql(dialect, shape.name)} ADD COLUMN ${quoteSql(dialect, name)} ${column.type}`,
|
|
303
|
+
params: []
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return missing;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
290
309
|
};
|
|
291
310
|
};
|
|
292
311
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_schema = require("../core/schema.cjs");
|
|
2
|
+
const require_fence = require("../database/fence.cjs");
|
|
2
3
|
const require_fixedMigratorShared = require("./fixedMigratorShared.cjs");
|
|
3
4
|
const require_settingsMigrator = require("./settingsMigrator.cjs");
|
|
4
5
|
const require_schemaSettings = require("./schemaSettings.cjs");
|
|
@@ -17,23 +18,45 @@ const createEngineMigrator = (options) => {
|
|
|
17
18
|
require_settingsMigrator.refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
18
19
|
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
19
20
|
if (changed.length === 0) {
|
|
21
|
+
const columns = await require_schemaSettings.addLateColumns(options.adapter, options.schema.tables, { dryRun: true });
|
|
20
22
|
const lacking = await require_schemaSettings.fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
21
|
-
if (lacking.length === 0) return require_fixedMigratorShared.getEmptyMigrationResult();
|
|
23
|
+
if (columns.length === 0 && lacking.length === 0) return require_fixedMigratorShared.getEmptyMigrationResult();
|
|
22
24
|
return {
|
|
23
|
-
operations: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
operations: [
|
|
26
|
+
...columns.map((column) => ({
|
|
27
|
+
type: "custom",
|
|
28
|
+
description: `Add column: ${column}`
|
|
29
|
+
})),
|
|
30
|
+
...columns.length === 0 ? [] : [{
|
|
31
|
+
type: "custom",
|
|
32
|
+
description: "Create the tables and indexes the database lacks"
|
|
33
|
+
}],
|
|
34
|
+
...lacking.length === 0 ? [] : [{
|
|
35
|
+
type: "custom",
|
|
36
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
37
|
+
}]
|
|
38
|
+
],
|
|
27
39
|
execute: async () => {
|
|
40
|
+
if (columns.length > 0) {
|
|
41
|
+
await require_schemaSettings.addLateColumns(options.adapter, options.schema.tables);
|
|
42
|
+
await options.adapter.migrations.apply([...options.schema.tables, require_fence.SETTINGS_TABLE]);
|
|
43
|
+
}
|
|
28
44
|
await require_schemaSettings.fillLateIndexes(options.adapter, options.schema.tables);
|
|
29
45
|
}
|
|
30
46
|
};
|
|
31
47
|
}
|
|
32
48
|
return {
|
|
33
|
-
operations: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
operations: [
|
|
50
|
+
...(await require_schemaSettings.addLateColumns(options.adapter, options.schema.tables, { dryRun: true }).catch(() => [])).map((column) => ({
|
|
51
|
+
type: "custom",
|
|
52
|
+
description: `Add column: ${column}`
|
|
53
|
+
})),
|
|
54
|
+
{
|
|
55
|
+
type: "custom",
|
|
56
|
+
description: "Create the tables and indexes the database lacks"
|
|
57
|
+
},
|
|
58
|
+
...migrate.updateSettings === false ? [] : [require_settingsMigrator.settingsOperation(stored, changed)]
|
|
59
|
+
],
|
|
37
60
|
execute: () => require_schemaSettings.migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
38
61
|
};
|
|
39
62
|
};
|