adding transacting to import raw query

This commit is contained in:
Bassel 2023-07-12 12:49:38 +03:00
parent d7e37899b7
commit 30e8a4e8bd

View File

@ -1,6 +1,7 @@
import { Writable, Readable } from 'stream'; import { Writable, Readable } from 'stream';
import * as fse from 'fs-extra'; import * as fse from 'fs-extra';
import path from 'path'; import path from 'path';
import type { Knex } from 'knex';
import type { import type {
IAsset, IAsset,
IDestinationProvider, IDestinationProvider,
@ -82,7 +83,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
return restore.deleteRecords(this.strapi, this.options.restore); return restore.deleteRecords(this.strapi, this.options.restore);
} }
async #deleteAllAssets() { async #deleteAllAssets(trx: Knex.Transaction) {
assertValidStrapi(this.strapi); assertValidStrapi(this.strapi);
const stream: Readable = strapi.db const stream: Readable = strapi.db
@ -90,6 +91,8 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
.queryBuilder('plugin::upload.file') .queryBuilder('plugin::upload.file')
// Fetch all columns // Fetch all columns
.select('*') .select('*')
// Attach the transaction
.transacting(trx)
// Get a readable stream // Get a readable stream
.stream(); .stream();
@ -113,11 +116,11 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
throw new Error('Strapi instance not found'); throw new Error('Strapi instance not found');
} }
await this.transaction?.attach(async () => { await this.transaction?.attach(async (trx) => {
await this.#handleAssetsBackup(); await this.#handleAssetsBackup();
try { try {
if (this.options.strategy === 'restore') { if (this.options.strategy === 'restore') {
await this.#deleteAllAssets(); await this.#deleteAllAssets(trx);
await this.#deleteAll(); await this.#deleteAll();
} }
} catch (error) { } catch (error) {