Skip to content

Commit

Permalink
Merge pull request #154 from desci-labs/drive-upgrade-gb
Browse files Browse the repository at this point in the history
update drive storage space default
  • Loading branch information
hubsmoke authored Nov 9, 2023
2 parents 7aaaff5 + 016b365 commit 9a14dc8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions desci-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"script:fix-data-refs": "debug=* NODE_PATH=./src ts-node-dev ./src/scripts/dataRefDoctor.ts",
"script:active-users": "debug=* NODE_PATH=./src ts-node-dev ./src/scripts/activeUsers.ts",
"script:invalidate-redis-cache": "debug=* NODE_PATH=./src ts-node-dev ./src/scripts/invalidate-redis-cache.ts",
"script:increase-base-drive-storage": "debug=* NODE_PATH=./src ts-node-dev ./src/scripts/increase-base-drive-storage.ts",
"build": "rimraf dist && tsc && yarn copy-files",
"copy-files": "copyfiles -u 1 src/**/*.cjs dist/",
"generate": "npx prisma generate",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "currentDriveStorageLimitGb" SET DEFAULT 100,
ALTER COLUMN "maxDriveStorageLimitGb" SET DEFAULT 500;
4 changes: 2 additions & 2 deletions desci-server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ model User {
CidPruneList CidPruneList[]
PublicDataReference PublicDataReference[]
FriendReferral FriendReferral[]
currentDriveStorageLimitGb Int @default(5)
maxDriveStorageLimitGb Int @default(250)
currentDriveStorageLimitGb Int @default(100)
maxDriveStorageLimitGb Int @default(500)
userOrganizations UserOrganizations[]
@@index([orcid])
Expand Down
60 changes: 60 additions & 0 deletions desci-server/src/scripts/increase-base-drive-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import dotenv from 'dotenv';

import prisma from 'client';
dotenv.config({ path: '../.env' });

export const increaseBaseDriveStoragePreview = async (targetDriveStorageGb: number, shouldApply: boolean) => {
const userCount = prisma.user.aggregate({
// prisma count aggregation
// https://www.prisma.io/docs/concepts/components/prisma-client/aggregation#count
_count: {
id: true,
},
where: {
currentDriveStorageLimitGb: {
lt: targetDriveStorageGb,
},
},
});

// get total users
const totalUserCount = await prisma.user.count();

const userStorageCount = prisma.$queryRaw`select count(1), "currentDriveStorageLimitGb" from "User" group by "currentDriveStorageLimitGb"`;

console.log(
`[increasesBaseDriveStorage] Affected users found: ${(await userCount)._count.id}/${totalUserCount} (${
Math.floor(((await userCount)._count.id / totalUserCount) * 10000) / 100
}%)`,
);

console.log(await userStorageCount);

if (shouldApply) {
// update users
const users = await prisma.user.updateMany({
where: {
currentDriveStorageLimitGb: {
lt: targetDriveStorageGb,
},
},
data: {
currentDriveStorageLimitGb: targetDriveStorageGb,
},
});
console.log(`[increasesBaseDriveStorage] Updated ${users.count} users`);
} else {
console.log(
`[increasesBaseDriveStorage] run with \`npm run script:increase-base-drive-storage ${targetDriveStorageGb} apply\` to apply changes`,
);
}
};

// get first arg
const targetDriveStorageGb = parseInt(process.argv[2]);
const shouldApply = process.argv[3] === 'apply';
console.log(process.argv);
console.log(`[increasesBaseDriveStorage] Target drive storage: ${targetDriveStorageGb} GB`);
increaseBaseDriveStoragePreview(targetDriveStorageGb, shouldApply)
.then((result) => console.log('Done running script', result))
.catch((err) => console.log('Error running script ', err));
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a14dc8

Please sign in to comment.