zerobucket 0.11.1 → 0.12.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/README.md +36 -23
- package/dist/bin.js +25 -5
- package/dist/index.cjs +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -162,9 +162,13 @@ declare class PostgresBackend implements StorageBackend {
|
|
|
162
162
|
* re-running is safe (already-migrated ids are skipped and reported, not an error). Classic rows
|
|
163
163
|
* already tiered to object storage are refused up front with a clear message (their bytes are
|
|
164
164
|
* not in the database to copy) unless `skipTiered: true`, which skips and counts them instead.
|
|
165
|
-
* Still all-or-nothing: one transaction
|
|
165
|
+
* Still all-or-nothing: one transaction, under an advisory lock (the Python package takes the same
|
|
166
|
+
* one since 0.34.0, so a Node and a Python migration of one database exclude each other).
|
|
167
|
+
* Both `created_at` and `updated_at` are kept exactly (before 0.12.0 `updated_at` became the time of
|
|
168
|
+
* the migration), and one `migrate_to_dedup` event is reported to `onOperation` (before 0.12.0, none).
|
|
166
169
|
*/
|
|
167
170
|
migrateClassicToDedup(opts?: MigrateToDedupOptions): Promise<MigrateToDedupResult>;
|
|
171
|
+
private migrateClassicToDedupInner;
|
|
168
172
|
private hydrate;
|
|
169
173
|
/**
|
|
170
174
|
* Remove tiered objects AFTER their rows are gone. Ordering is deliberate:
|
package/dist/index.d.ts
CHANGED
|
@@ -162,9 +162,13 @@ declare class PostgresBackend implements StorageBackend {
|
|
|
162
162
|
* re-running is safe (already-migrated ids are skipped and reported, not an error). Classic rows
|
|
163
163
|
* already tiered to object storage are refused up front with a clear message (their bytes are
|
|
164
164
|
* not in the database to copy) unless `skipTiered: true`, which skips and counts them instead.
|
|
165
|
-
* Still all-or-nothing: one transaction
|
|
165
|
+
* Still all-or-nothing: one transaction, under an advisory lock (the Python package takes the same
|
|
166
|
+
* one since 0.34.0, so a Node and a Python migration of one database exclude each other).
|
|
167
|
+
* Both `created_at` and `updated_at` are kept exactly (before 0.12.0 `updated_at` became the time of
|
|
168
|
+
* the migration), and one `migrate_to_dedup` event is reported to `onOperation` (before 0.12.0, none).
|
|
166
169
|
*/
|
|
167
170
|
migrateClassicToDedup(opts?: MigrateToDedupOptions): Promise<MigrateToDedupResult>;
|
|
171
|
+
private migrateClassicToDedupInner;
|
|
168
172
|
private hydrate;
|
|
169
173
|
/**
|
|
170
174
|
* Remove tiered objects AFTER their rows are gone. Ordering is deliberate:
|
package/dist/index.js
CHANGED
|
@@ -879,7 +879,10 @@ var PostgresBackend = class {
|
|
|
879
879
|
* re-running is safe (already-migrated ids are skipped and reported, not an error). Classic rows
|
|
880
880
|
* already tiered to object storage are refused up front with a clear message (their bytes are
|
|
881
881
|
* not in the database to copy) unless `skipTiered: true`, which skips and counts them instead.
|
|
882
|
-
* Still all-or-nothing: one transaction
|
|
882
|
+
* Still all-or-nothing: one transaction, under an advisory lock (the Python package takes the same
|
|
883
|
+
* one since 0.34.0, so a Node and a Python migration of one database exclude each other).
|
|
884
|
+
* Both `created_at` and `updated_at` are kept exactly (before 0.12.0 `updated_at` became the time of
|
|
885
|
+
* the migration), and one `migrate_to_dedup` event is reported to `onOperation` (before 0.12.0, none).
|
|
883
886
|
*/
|
|
884
887
|
async migrateClassicToDedup(opts = {}) {
|
|
885
888
|
if (!this.dedup) {
|
|
@@ -887,6 +890,17 @@ var PostgresBackend = class {
|
|
|
887
890
|
"migrateClassicToDedup() must be called on an instance created with dedup: true."
|
|
888
891
|
);
|
|
889
892
|
}
|
|
893
|
+
const start = performance.now();
|
|
894
|
+
try {
|
|
895
|
+
const result = await this.migrateClassicToDedupInner(opts);
|
|
896
|
+
this.emit("migrate_to_dedup", start, true, null, 0);
|
|
897
|
+
return result;
|
|
898
|
+
} catch (exc) {
|
|
899
|
+
this.emit("migrate_to_dedup", start, false, msg(exc), 0);
|
|
900
|
+
throw exc;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
async migrateClassicToDedupInner(opts) {
|
|
890
904
|
await this.ready();
|
|
891
905
|
const client = await this.pool.connect();
|
|
892
906
|
let destroy = false;
|
|
@@ -923,11 +937,11 @@ var PostgresBackend = class {
|
|
|
923
937
|
const BATCH = 20;
|
|
924
938
|
for (; ; ) {
|
|
925
939
|
const page = cursor ? await client.query(
|
|
926
|
-
`SELECT id, data, mime_type, original_filename, size_bytes, width, height, checksum_sha256, created_at::text AS created_at_txt
|
|
940
|
+
`SELECT id, data, mime_type, original_filename, size_bytes, width, height, checksum_sha256, created_at::text AS created_at_txt, updated_at::text AS updated_at_txt
|
|
927
941
|
FROM zerobucket_images WHERE (created_at, id) > ($1::timestamptz, $2::uuid)${onlyInDb ? " AND storage_backend = 'postgres'" : ""} ORDER BY created_at, id LIMIT ${BATCH}`,
|
|
928
942
|
[cursor.createdAt, cursor.id]
|
|
929
943
|
) : await client.query(
|
|
930
|
-
`SELECT id, data, mime_type, original_filename, size_bytes, width, height, checksum_sha256, created_at::text AS created_at_txt
|
|
944
|
+
`SELECT id, data, mime_type, original_filename, size_bytes, width, height, checksum_sha256, created_at::text AS created_at_txt, updated_at::text AS updated_at_txt
|
|
931
945
|
FROM zerobucket_images${onlyInDb ? " WHERE storage_backend = 'postgres'" : ""} ORDER BY created_at, id LIMIT ${BATCH}`
|
|
932
946
|
);
|
|
933
947
|
if (page.rows.length === 0) break;
|
|
@@ -966,8 +980,14 @@ var PostgresBackend = class {
|
|
|
966
980
|
}
|
|
967
981
|
for (const r of fresh) {
|
|
968
982
|
await client.query(
|
|
969
|
-
"INSERT INTO zerobucket_image_refs (id, checksum_sha256, original_filename, created_at) VALUES ($1, $2, $3, $4::timestamptz)",
|
|
970
|
-
[
|
|
983
|
+
"INSERT INTO zerobucket_image_refs (id, checksum_sha256, original_filename, created_at, updated_at) VALUES ($1, $2, $3, $4::timestamptz, $5::timestamptz)",
|
|
984
|
+
[
|
|
985
|
+
r.id,
|
|
986
|
+
r.checksum_sha256,
|
|
987
|
+
r.original_filename,
|
|
988
|
+
r.created_at_txt,
|
|
989
|
+
r.updated_at_txt
|
|
990
|
+
]
|
|
971
991
|
);
|
|
972
992
|
seen.add(r.checksum_sha256);
|
|
973
993
|
migrated += 1;
|