Skip to content

Commit b375366

Browse files
author
Andres Pinto
committed
chore: add seeder to modify gigabytes to bytes
1 parent 8f02004 commit b375366

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
module.exports = {
4+
async up(queryInterface, Sequelize) {
5+
const convertGbToBytes = (gbValue) => gbValue * 1024 * 1024 * 1024;
6+
7+
const maxFileUploadSizeLimits = await queryInterface.sequelize.query(
8+
"SELECT id, value FROM limits WHERE label = 'max-file-upload-size'",
9+
{ type: Sequelize.QueryTypes.SELECT },
10+
);
11+
12+
for (const limit of maxFileUploadSizeLimits) {
13+
const bytesValue = convertGbToBytes(parseInt(limit.value)).toString();
14+
15+
await queryInterface.sequelize.query(
16+
'UPDATE limits SET value = :bytesValue WHERE id = :id',
17+
{
18+
replacements: { bytesValue, id: limit.id },
19+
type: Sequelize.QueryTypes.UPDATE,
20+
},
21+
);
22+
}
23+
},
24+
25+
async down(queryInterface, Sequelize) {
26+
const convertBytesToGB = (gbValue) => gbValue / 1024 / 1024 / 1024;
27+
28+
const maxFileUploadSizeLimits = await queryInterface.sequelize.query(
29+
"SELECT id, value FROM limits WHERE label = 'max-file-upload-size'",
30+
{ type: Sequelize.QueryTypes.SELECT },
31+
);
32+
33+
for (const limit of maxFileUploadSizeLimits) {
34+
const bytesValue = convertBytesToGB(parseInt(limit.value)).toString();
35+
36+
await queryInterface.sequelize.query(
37+
'UPDATE limits SET value = :bytesValue WHERE id = :id',
38+
{
39+
replacements: { bytesValue, id: limit.id },
40+
type: Sequelize.QueryTypes.UPDATE,
41+
},
42+
);
43+
}
44+
},
45+
};

0 commit comments

Comments
 (0)