chore: initial import
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
||||
const db = require('../db');
|
||||
|
||||
async function listSchema() {
|
||||
try {
|
||||
const res = await db.query(`
|
||||
SELECT
|
||||
table_name,
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
table_schema = 'public'
|
||||
ORDER BY
|
||||
table_name, ordinal_position
|
||||
`);
|
||||
|
||||
const tables = {};
|
||||
res.rows.forEach(row => {
|
||||
if (!tables[row.table_name]) {
|
||||
tables[row.table_name] = [];
|
||||
}
|
||||
tables[row.table_name].push({
|
||||
column: row.column_name,
|
||||
type: row.data_type,
|
||||
nullable: row.is_nullable
|
||||
});
|
||||
});
|
||||
|
||||
console.log('--- 数据库全量表结构 ---');
|
||||
for (const [tableName, columns] of Object.entries(tables)) {
|
||||
console.log(`\n表名: ${tableName}`);
|
||||
console.table(columns);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('查询失败:', err);
|
||||
} finally {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
listSchema();
|
||||
Reference in New Issue
Block a user