Files
tg_tinder_bot/scripts/checkUserTable.js
2025-09-18 13:46:35 +09:00

75 lines
2.7 KiB
JavaScript
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.

const { Pool } = require('pg');
require('dotenv').config();
const pool = new Pool({
user: process.env.DB_USER || 'postgres',
host: process.env.DB_HOST || 'localhost',
database: process.env.DB_NAME || 'telegram_tinder_db',
password: process.env.DB_PASSWORD || 'postgres',
port: parseInt(process.env.DB_PORT || '5432')
});
async function checkUserTableStructure() {
try {
// Получаем информацию о структуре таблицы users
const result = await pool.query(`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'users'
ORDER BY ordinal_position;
`);
console.log('=== Структура таблицы users ===');
console.table(result.rows);
// Проверяем наличие столбцов state и state_data
const stateColumn = result.rows.find(row => row.column_name === 'state');
const stateDataColumn = result.rows.find(row => row.column_name === 'state_data');
if (!stateColumn) {
console.log('❌ Столбец state отсутствует в таблице users');
} else {
console.log('✅ Столбец state присутствует в таблице users');
}
if (!stateDataColumn) {
console.log('❌ Столбец state_data отсутствует в таблице users');
} else {
console.log('✅ Столбец state_data присутствует в таблице users');
}
// Добавляем эти столбцы, если их нет
if (!stateColumn || !stateDataColumn) {
console.log('🔄 Добавление отсутствующих столбцов...');
await pool.query(`
ALTER TABLE users
ADD COLUMN IF NOT EXISTS state VARCHAR(255) NULL,
ADD COLUMN IF NOT EXISTS state_data JSONB DEFAULT '{}'::jsonb;
`);
console.log('✅ Столбцы успешно добавлены');
}
// Проверяем наличие других таблиц, связанных с уведомлениями
const tablesResult = await pool.query(`
SELECT tablename
FROM pg_catalog.pg_tables
WHERE schemaname = 'public'
AND tablename IN ('notifications', 'notification_settings', 'scheduled_notifications');
`);
console.log('\n=== Таблицы для уведомлений ===');
console.table(tablesResult.rows);
// Закрываем соединение
await pool.end();
} catch (error) {
console.error('Ошибка при проверке структуры таблицы:', error);
await pool.end();
}
}
checkUserTableStructure();