Files
tg_tinder_bot/src/scripts/getDatabaseInfo.ts
2025-09-18 08:31:14 +09:00

121 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Pool } from 'pg';
import 'dotenv/config';
async function getDatabaseInfo() {
const pool = new Pool({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || '5432'),
database: process.env.DB_NAME,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD
});
try {
console.log('Подключение к базе данных...');
// Получаем информацию о пользователях
console.log('\n=== ПОЛЬЗОВАТЕЛИ ===');
const usersResult = await pool.query(`
SELECT id, telegram_id, username, first_name, last_name, premium, created_at
FROM users
ORDER BY created_at DESC
`);
console.log(`Всего пользователей: ${usersResult.rows.length}`);
console.table(usersResult.rows);
// Получаем информацию о профилях
console.log('\n=== ПРОФИЛИ ===');
const profilesResult = await pool.query(`
SELECT
p.user_id,
u.telegram_id,
u.first_name,
p.age,
p.gender,
p.interested_in as "интересуется",
p.bio,
p.dating_goal as "цель_знакомства",
p.is_visible,
p.created_at
FROM profiles p
JOIN users u ON p.user_id = u.id
ORDER BY p.created_at DESC
`);
console.log(`Всего профилей: ${profilesResult.rows.length}`);
console.table(profilesResult.rows);
// Получаем информацию о свайпах
console.log('\n=== СВАЙПЫ ===');
// Сначала проверим, какие столбцы есть в таблице swipes
console.log('Получение структуры таблицы swipes...');
const swipesColumns = await pool.query(`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'swipes'
`);
console.log('Структура таблицы swipes:');
console.table(swipesColumns.rows);
// Теперь запросим данные, используя правильные имена столбцов
const swipesResult = await pool.query(`
SELECT
s.id,
s.user_id,
u1.first_name as "от_кого",
s.target_user_id,
u2.first_name as "кому",
s.type,
s.created_at
FROM swipes s
JOIN users u1 ON s.user_id = u1.id
JOIN users u2 ON s.target_user_id = u2.id
ORDER BY s.created_at DESC
`);
console.log(`Всего свайпов: ${swipesResult.rows.length}`);
console.table(swipesResult.rows);
// Получаем информацию о матчах
console.log('\n=== МАТЧИ ===');
// Сначала проверим, какие столбцы есть в таблице matches
console.log('Получение структуры таблицы matches...');
const matchesColumns = await pool.query(`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'matches'
`);
console.log('Структура таблицы matches:');
console.table(matchesColumns.rows);
// Теперь запросим данные, используя правильные имена столбцов
const matchesResult = await pool.query(`
SELECT
m.id,
m.user_id_1,
u1.first_name as "пользователь_1",
m.user_id_2,
u2.first_name as "пользователь_2",
m.is_active,
m.created_at
FROM matches m
JOIN users u1 ON m.user_id_1 = u1.id
JOIN users u2 ON m.user_id_2 = u2.id
ORDER BY m.created_at DESC
`);
console.log(`Всего матчей: ${matchesResult.rows.length}`);
console.table(matchesResult.rows);
} catch (error) {
console.error('Ошибка при получении данных:', error);
} finally {
await pool.end();
}
}
getDatabaseInfo();