@madewithremy/admin 0.1.60 → 0.1.62
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/CHANGELOG.md +19 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +2 -2
- package/dist/ops/data.d.ts +2 -0
- package/dist/ops/db.d.ts +27 -9
- package/dist/prod.js +45 -13
- package/dist/types/db.d.ts +15 -1
- package/package.json +1 -1
package/dist/ops/data.d.ts
CHANGED
|
@@ -58,6 +58,8 @@ export interface LiftFromLiveParams {
|
|
|
58
58
|
*
|
|
59
59
|
* @throws AdminApiError `no_dev_session` (404) — no dev release exists (start a dev session first);
|
|
60
60
|
* `no_live_release` (404) — no live release (copy mode only; not thrown when `truncate` is true);
|
|
61
|
+
* `live_too_large_to_copy` (422) — live's databases are past the 1 GB that may be copied into dev
|
|
62
|
+
* (copy mode only): seed dev with scenarios instead;
|
|
61
63
|
* `not_your_dev_session` (403) — `releaseId` names someone else's dev session.
|
|
62
64
|
* @example
|
|
63
65
|
* // Pull live data into dev for debugging:
|
package/dist/ops/db.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* all output.
|
|
7
7
|
*/
|
|
8
8
|
import type { AdminContext } from '../ctx.js';
|
|
9
|
-
import type { DbHistoryResult, DbQueryResult } from '../types/db.js';
|
|
9
|
+
import type { DbHistoryPurgeResult, DbHistoryResult, DbQueryResult } from '../types/db.js';
|
|
10
10
|
/**
|
|
11
11
|
* Execute one SQL statement against the app's live-release database.
|
|
12
12
|
*
|
|
@@ -35,13 +35,15 @@ export interface DbHistoryParams {
|
|
|
35
35
|
cursor?: string;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* The app's releases that were ever live
|
|
39
|
-
* it was live for and its
|
|
38
|
+
* The app's releases that were ever live and still keep a copy of the
|
|
39
|
+
* database, newest first, each with the window it was live for and its
|
|
40
|
+
* databases.
|
|
40
41
|
*
|
|
41
42
|
* A deploy copies live into the new release and keeps the release it
|
|
42
|
-
* replaces, database and all, as it stood at that moment
|
|
43
|
-
* database is live as of its `liveUntil`; the
|
|
44
|
-
* with `current: true`. Nothing between two
|
|
43
|
+
* replaces, database and all, as it stood at that moment, until its
|
|
44
|
+
* `keptUntil`. So each entry's database is live as of its `liveUntil`; the
|
|
45
|
+
* release live now heads the list with `current: true`. Nothing between two
|
|
46
|
+
* deploys is kept.
|
|
45
47
|
*
|
|
46
48
|
* @throws AdminApiError `invalid_request` (400) — `limit` isn't an integer.
|
|
47
49
|
* @example
|
|
@@ -56,8 +58,9 @@ export declare function history(ctx: AdminContext, params?: DbHistoryParams): Pr
|
|
|
56
58
|
* @param releaseId A release from `history()` that isn't `current`.
|
|
57
59
|
* @throws AdminApiError `release_not_found` (404) — no release of this app
|
|
58
60
|
* that was ever live has that id; `release_is_live` (400) — it's the live
|
|
59
|
-
* release, so use `query`; `
|
|
60
|
-
*
|
|
61
|
+
* release, so use `query`; `copy_expired` (404) — that release's copy was
|
|
62
|
+
* deleted, its window passed or purged; `no_database` (404) — that release
|
|
63
|
+
* has no database of live's name; `no_live_release` (404) — the app isn't
|
|
61
64
|
* deployed; `sql_error` (400) — the database refused the statement,
|
|
62
65
|
* a write included.
|
|
63
66
|
* @example
|
|
@@ -71,11 +74,26 @@ export declare function historyQuery(ctx: AdminContext, releaseId: string, sql:
|
|
|
71
74
|
* run in one transaction; the attached copy is private to the call, so
|
|
72
75
|
* nothing written into it lasts.
|
|
73
76
|
*
|
|
77
|
+
* A past database larger than 1 GB can't be attached: read it with
|
|
78
|
+
* `historyQuery` instead, and write what's needed to live with `query`.
|
|
79
|
+
*
|
|
74
80
|
* @param releaseId A release from `history()` that isn't `current`.
|
|
75
81
|
* @throws AdminApiError the same as `historyQuery`; a `sql_error` is the
|
|
76
|
-
* database refusing the statement,
|
|
82
|
+
* database refusing the statement, or a past database too large to attach,
|
|
83
|
+
* or a server with no room to copy it right now, and nothing was applied.
|
|
77
84
|
* @example
|
|
78
85
|
* await admin.db.historyAttach(releaseId,
|
|
79
86
|
* 'UPDATE orders SET note = h.note FROM history.orders h WHERE h.id = orders.id AND orders.note IS NULL');
|
|
80
87
|
*/
|
|
81
88
|
export declare function historyAttach(ctx: AdminContext, releaseId: string, sql: string): Promise<DbQueryResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Delete every copy of the database the app's replaced releases keep, now,
|
|
91
|
+
* rather than when each one's window passes: for a deletion that can't wait.
|
|
92
|
+
* Live is untouched, and `history` lists only the live release afterwards.
|
|
93
|
+
*
|
|
94
|
+
* @throws AdminApiError `app_moving` (503) — the app's data is moving between
|
|
95
|
+
* workspaces or regions; try again once the move is done.
|
|
96
|
+
* @example
|
|
97
|
+
* const { purged } = await admin.db.historyPurge();
|
|
98
|
+
*/
|
|
99
|
+
export declare function historyPurge(ctx: AdminContext): Promise<DbHistoryPurgeResult>;
|
package/dist/prod.js
CHANGED
|
@@ -2283,6 +2283,14 @@ function historyAttach(ctx, releaseId, sql) {
|
|
|
2283
2283
|
{ releaseId, queries: [{ sql }] }
|
|
2284
2284
|
);
|
|
2285
2285
|
}
|
|
2286
|
+
function historyPurge(ctx) {
|
|
2287
|
+
return call(
|
|
2288
|
+
ctx,
|
|
2289
|
+
"POST",
|
|
2290
|
+
`/_internal/v2/apps/${ctx.appId}/db/history/purge`,
|
|
2291
|
+
{}
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2286
2294
|
|
|
2287
2295
|
// src/commands/db.ts
|
|
2288
2296
|
var dbSpecs = {
|
|
@@ -2319,6 +2327,9 @@ var dbSpecs = {
|
|
|
2319
2327
|
{ name: "releaseId", required: true },
|
|
2320
2328
|
{ name: "sql", required: true }
|
|
2321
2329
|
]
|
|
2330
|
+
},
|
|
2331
|
+
"db history purge": {
|
|
2332
|
+
usage: "Usage: remy-admin db history purge"
|
|
2322
2333
|
}
|
|
2323
2334
|
};
|
|
2324
2335
|
async function dbQuery(ctx, a) {
|
|
@@ -2335,6 +2346,9 @@ async function dbHistoryQuery(ctx, a) {
|
|
|
2335
2346
|
async function dbHistoryAttach(ctx, a) {
|
|
2336
2347
|
out(await historyAttach(ctx, a.req("releaseId"), a.req("sql")));
|
|
2337
2348
|
}
|
|
2349
|
+
async function dbHistoryPurge(ctx) {
|
|
2350
|
+
out(await historyPurge(ctx));
|
|
2351
|
+
}
|
|
2338
2352
|
async function dbTables(ctx) {
|
|
2339
2353
|
out(
|
|
2340
2354
|
await query2(
|
|
@@ -2348,16 +2362,18 @@ var dbHandlers = {
|
|
|
2348
2362
|
"db tables": dbTables,
|
|
2349
2363
|
"db history": dbHistory,
|
|
2350
2364
|
"db history query": dbHistoryQuery,
|
|
2351
|
-
"db history attach": dbHistoryAttach
|
|
2365
|
+
"db history attach": dbHistoryAttach,
|
|
2366
|
+
"db history purge": dbHistoryPurge
|
|
2352
2367
|
};
|
|
2353
2368
|
var dbHelp = `remy-admin db \u2014 Query the production database, and the copies of it past releases kept.
|
|
2354
2369
|
|
|
2355
2370
|
Subcommands:
|
|
2356
2371
|
query Execute a SQL query against the live release's database
|
|
2357
2372
|
tables List all tables in the database
|
|
2358
|
-
history List past releases
|
|
2373
|
+
history List the copies past releases keep, newest first, with when each was live
|
|
2359
2374
|
history query Read a past release's database (read-only)
|
|
2360
2375
|
history attach Run SQL against live with a past release's database attached as "history"
|
|
2376
|
+
history purge Delete every copy past releases keep, now
|
|
2361
2377
|
|
|
2362
2378
|
Usage:
|
|
2363
2379
|
remy-admin db <sql>
|
|
@@ -2366,14 +2382,17 @@ Usage:
|
|
|
2366
2382
|
remy-admin db history [--limit 20] [--cursor <nextCursor>]
|
|
2367
2383
|
remy-admin db history query <releaseId> <sql>
|
|
2368
2384
|
remy-admin db history attach <releaseId> <sql>
|
|
2385
|
+
remy-admin db history purge
|
|
2369
2386
|
|
|
2370
2387
|
Past releases:
|
|
2371
2388
|
Every deploy copies the live database into the new release and keeps the
|
|
2372
|
-
release it replaces, database and all, exactly as it stood at that moment
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2389
|
+
release it replaces, database and all, exactly as it stood at that moment,
|
|
2390
|
+
until its keptUntil: 28 days after it was replaced, when the copy is
|
|
2391
|
+
deleted. So each entry 'db history' lists holds live as of its liveUntil:
|
|
2392
|
+
anything written after that is only in later copies and in live, and
|
|
2393
|
+
nothing that happened between two deploys is kept anywhere. The release
|
|
2394
|
+
live now is listed first (current: true); its database is live, so use
|
|
2395
|
+
'db query'.
|
|
2377
2396
|
|
|
2378
2397
|
'db history query' reads one of those copies, and nothing can change it: a
|
|
2379
2398
|
write is refused. Its schema is that release's, which may differ from
|
|
@@ -2386,6 +2405,10 @@ Past releases:
|
|
|
2386
2405
|
statement runs as one transaction. The attached copy is private to the
|
|
2387
2406
|
call, so writing into it changes nothing anywhere.
|
|
2388
2407
|
PRAGMA history.table_info(<table>) shows a past table's columns.
|
|
2408
|
+
A past database larger than 1 GB can't be attached, and the sql_error says
|
|
2409
|
+
so: read what you need from it with 'db history query', then write that to
|
|
2410
|
+
live with 'db query'. One the server has no room to copy right now says
|
|
2411
|
+
that instead; try again shortly.
|
|
2389
2412
|
|
|
2390
2413
|
Recovering data is a merge, not a rollback. Live has moved on since the
|
|
2391
2414
|
copy was made (rows added, edits people meant to make), so decide what
|
|
@@ -2409,6 +2432,11 @@ Past releases:
|
|
|
2409
2432
|
If no copy covers the moment that matters, say so plainly rather than
|
|
2410
2433
|
restoring from the nearest one.
|
|
2411
2434
|
|
|
2435
|
+
'db history purge' deletes every copy now, for a deletion request that
|
|
2436
|
+
can't wait the 28 days: rows deleted from live then leave every copy at
|
|
2437
|
+
once. Live is untouched, and nothing can bring a purged copy back, so get
|
|
2438
|
+
the user's go-ahead first.
|
|
2439
|
+
|
|
2412
2440
|
Notes:
|
|
2413
2441
|
- SQL is taken verbatim: 'db query' and the two history commands that take
|
|
2414
2442
|
SQL don't parse flags, so a statement may safely begin with a '--'
|
|
@@ -2418,9 +2446,11 @@ Notes:
|
|
|
2418
2446
|
large database; the ones after it are quick.
|
|
2419
2447
|
- Errors: release_not_found (no release of this app that was ever live has
|
|
2420
2448
|
that id), release_is_live (it's the live release: use 'db query'),
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2449
|
+
copy_expired (that release's copy was deleted: its 28 days passed, or it
|
|
2450
|
+
was purged), no_database (that release has no database of live's name),
|
|
2451
|
+
sql_error (the database refused the statement, a write to a past copy
|
|
2452
|
+
included; nothing in it was applied), app_moving (purge: the app's data
|
|
2453
|
+
is moving; try again once the move is done).
|
|
2424
2454
|
|
|
2425
2455
|
Examples:
|
|
2426
2456
|
remy-admin db tables
|
|
@@ -2939,9 +2969,11 @@ What lift-from-live does:
|
|
|
2939
2969
|
The reverse \u2014 pulls live's databases down over dev's, so the sandbox matches
|
|
2940
2970
|
prod. Useful for reproducing a prod bug against real data or re-syncing a
|
|
2941
2971
|
stale sandbox. Only dev is overwritten; live/prod data is never touched.
|
|
2942
|
-
Requires an existing dev release (start a dev session first).
|
|
2943
|
-
|
|
2944
|
-
|
|
2972
|
+
Requires an existing dev release (start a dev session first). Refused with
|
|
2973
|
+
live_too_large_to_copy once live's databases are past 1 GB: seed dev with
|
|
2974
|
+
scenarios instead. With --truncate it instead empties the dev databases
|
|
2975
|
+
(keeps schema + IDs, no data pulled from live). Writes an audit row tagged
|
|
2976
|
+
'lift-live-to-dev'.
|
|
2945
2977
|
|
|
2946
2978
|
Critical constraints:
|
|
2947
2979
|
- Whole-database overwrite, INCLUDING auth tables. lift-from-dev wipes live's
|
package/dist/types/db.d.ts
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* (PublishedRelease, AppReleases/types/release.ts)
|
|
10
10
|
* POST /db/history/query, /db/history/attach → the same file; answered as
|
|
11
11
|
* /db/query is
|
|
12
|
+
* POST /db/history/purge → the same file, over AppDatabases/recoveryCopies.ts
|
|
12
13
|
*/
|
|
13
14
|
/**
|
|
14
15
|
* Response from GET /_internal/v2/apps/:appId/db/history: the app's releases
|
|
15
|
-
* that were ever live
|
|
16
|
+
* that were ever live and still keep a copy of the database, newest first,
|
|
17
|
+
* with the window each was live for.
|
|
16
18
|
*/
|
|
17
19
|
export interface DbHistoryResult {
|
|
18
20
|
copies: Array<{
|
|
@@ -27,6 +29,11 @@ export interface DbHistoryResult {
|
|
|
27
29
|
* stood at that moment. Null for the release live now.
|
|
28
30
|
*/
|
|
29
31
|
liveUntil: string | null;
|
|
32
|
+
/**
|
|
33
|
+
* When this copy is deleted (ISO): a replaced release's copy is kept for a
|
|
34
|
+
* window after it's replaced. Null for the release live now.
|
|
35
|
+
*/
|
|
36
|
+
keptUntil: string | null;
|
|
30
37
|
/** The release live now, whose database is live: query it with `db query`. */
|
|
31
38
|
current: boolean;
|
|
32
39
|
/** The release's databases; history commands use the one named as live's default. */
|
|
@@ -61,3 +68,10 @@ export interface DbQueryResult {
|
|
|
61
68
|
profilePictureUrl: string | null;
|
|
62
69
|
}>;
|
|
63
70
|
}
|
|
71
|
+
/** Response from POST /_internal/v2/apps/:appId/db/history/purge. */
|
|
72
|
+
export interface DbHistoryPurgeResult {
|
|
73
|
+
/** The releases whose copies were deleted. */
|
|
74
|
+
purged: Array<{
|
|
75
|
+
releaseId: string;
|
|
76
|
+
}>;
|
|
77
|
+
}
|