2021-08-19 14:55:45 +02:00
|
|
|
import define from '../../define';
|
2019-06-18 09:49:58 +02:00
|
|
|
import { getConnection } from 'typeorm';
|
|
|
|
|
|
|
|
export const meta = {
|
2020-03-30 04:45:57 +02:00
|
|
|
requireCredential: true as const,
|
2020-10-17 13:12:00 +02:00
|
|
|
requireModerator: true,
|
2019-06-18 09:49:58 +02:00
|
|
|
|
2020-04-03 15:42:29 +02:00
|
|
|
tags: ['admin'],
|
2019-06-18 09:49:58 +02:00
|
|
|
|
|
|
|
params: {
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
example: {
|
|
|
|
migrations: {
|
|
|
|
count: 66,
|
2021-12-09 15:58:30 +01:00
|
|
|
size: 32768,
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
2019-06-18 09:49:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async () => {
|
|
|
|
const sizes = await
|
|
|
|
getConnection().query(`
|
|
|
|
SELECT relname AS "table", reltuples as "count", pg_total_relation_size(C.oid) AS "size"
|
|
|
|
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
|
|
|
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
|
|
|
|
AND C.relkind <> 'i'
|
|
|
|
AND nspname !~ '^pg_toast';`)
|
|
|
|
.then(recs => {
|
|
|
|
const res = {} as Record<string, { count: number; size: number; }>;
|
|
|
|
for (const rec of recs) {
|
|
|
|
res[rec.table] = {
|
|
|
|
count: parseInt(rec.count, 10),
|
|
|
|
size: parseInt(rec.size, 10),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes;
|
|
|
|
});
|