Skip to content

Commit

Permalink
fix: disable s3 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
achauve committed Oct 14, 2024
1 parent bcee2ef commit b648a2f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fileignoreconfig:
- filename: packages/migrations/src/migrations/20240710125537_eig.js
checksum: c358c5f8cf7a408173e9ff8d273f05c8e1a193c3369ec2389bfd713ff1bab716
- filename: packages/migrations/src/migrations/20240918085236_migrate_files_to_minio.js
checksum: 697b937bde70ecf883bfc42137bf7bb34924dc860546cc0fc525d75c32f252b2
checksum: ce0b678503f6342414ed759fa31ac460060d1efd1daadffb3d7be0bfa049858c
- filename: packages/shared/src/components/Chat.vue
checksum: f2dbbf72bf098c7abd2c3aee230d220f5a5a106952883c0e116eb49f4f9d4db7
- filename: packages/shared/src/components/PasswordInput.vue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,63 @@ const s3Client = new S3Client({
* @returns { Promise<void> }
*/
exports.up = (knex) => {
console.log("Migrating files to S3");
console.log("S3_BUCKET_NAME", S3_BUCKET_NAME);
console.log("S3_BUCKET_ROOT_DIR", S3_BUCKET_ROOT_DIR);
return knex
.withSchema("doc")
.select()
.from("documents")
.then(async (rows) => {
for (const row of rows) {
const objectKey = `${S3_BUCKET_ROOT_DIR}/${row.uuid}.pdf`;

try {
// Check if the file already exists
await s3Client.send(
new HeadObjectCommand({
Bucket: S3_BUCKET_NAME,
Key: objectKey,
}),
);

// If the file exists, log it and skip the upload
console.log(`File ${objectKey} already exists. Skipping upload.`);
continue;
} catch (err) {
// If a 404 error occurs, the file doesn't exist, proceed with upload
if (err.name === "NotFound") {
try {
// Upload the file since it doesn't exist
await s3Client.send(
new PutObjectCommand({
Body: row.file,
Bucket: S3_BUCKET_NAME,
Key: objectKey,
Metadata: {
category: String(row.category),
created_at: String(row.created_at),
mimetype: String(row.mime_type),
originalname: String(row.filename),
},
}),
);
console.log(`Uploaded ${objectKey}`);
} catch (uploadErr) {
console.error(`Failed to upload ${objectKey}:`, uploadErr);
throw uploadErr;
}
} else {
// If the error isn't a 404, throw it to handle other failures
console.error(`Error checking existence of ${objectKey}:`, err);
throw err;
}
}
}
})
.catch((err) => {
// Catch the error and rethrow it to ensure the migration fails
console.error("Migration failed:", err);
throw err;
});
// console.log("Migrating files to S3");
// console.log("S3_BUCKET_NAME", S3_BUCKET_NAME);
// console.log("S3_BUCKET_ROOT_DIR", S3_BUCKET_ROOT_DIR);
// return knex
// .withSchema("doc")
// .select()
// .from("documents")
// .then(async (rows) => {
// for (const row of rows) {
// const objectKey = `${S3_BUCKET_ROOT_DIR}/${row.uuid}.pdf`;
// try {
// // Check if the file already exists
// await s3Client.send(
// new HeadObjectCommand({
// Bucket: S3_BUCKET_NAME,
// Key: objectKey,
// }),
// );
// // If the file exists, log it and skip the upload
// console.log(`File ${objectKey} already exists. Skipping upload.`);
// continue;
// } catch (err) {
// // If a 404 error occurs, the file doesn't exist, proceed with upload
// if (err.name === "NotFound") {
// try {
// // Upload the file since it doesn't exist
// await s3Client.send(
// new PutObjectCommand({
// Body: row.file,
// Bucket: S3_BUCKET_NAME,
// Key: objectKey,
// Metadata: {
// category: String(row.category),
// created_at: String(row.created_at),
// mimetype: String(row.mime_type),
// originalname: String(row.filename),
// },
// }),
// );
// console.log(`Uploaded ${objectKey}`);
// } catch (uploadErr) {
// console.error(`Failed to upload ${objectKey}:`, uploadErr);
// throw uploadErr;
// }
// } else {
// // If the error isn't a 404, throw it to handle other failures
// console.error(`Error checking existence of ${objectKey}:`, err);
// throw err;
// }
// }
// }
// })
// .catch((err) => {
// // Catch the error and rethrow it to ensure the migration fails
// console.error("Migration failed:", err);
// throw err;
// });
};

/**
Expand Down

0 comments on commit b648a2f

Please sign in to comment.