-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from desci-labs/drive-upgrade-gb
update drive storage space default
- Loading branch information
Showing
5 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
desci-server/prisma/migrations/20231108232618_default_drive_gb/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.