forked from mtusi2026/mtusi2026lab6
29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import {
|
|
BucketAlreadyOwnedByYou,
|
|
CreateBucketCommand,
|
|
S3Client,
|
|
} from '@aws-sdk/client-s3';
|
|
import { execSync } from 'child_process';
|
|
|
|
export default async function globalSetup(): Promise<void> {
|
|
execSync('npx prisma migrate deploy', { stdio: 'inherit' });
|
|
const client = new S3Client({
|
|
endpoint: process.env.S3_ENDPOINT,
|
|
region: 'us-east-1',
|
|
forcePathStyle: true,
|
|
credentials: {
|
|
accessKeyId: process.env.S3_ACCESS_KEY_ID!,
|
|
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY!,
|
|
},
|
|
});
|
|
try {
|
|
await client.send(new CreateBucketCommand({ Bucket: process.env.S3_BUCKET! }));
|
|
} catch (error) {
|
|
if (!(error instanceof BucketAlreadyOwnedByYou)) {
|
|
throw error;
|
|
}
|
|
} finally {
|
|
client.destroy();
|
|
}
|
|
}
|