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

59 lines
2.2 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.

// Скрипт для добавления колонки premium в таблицу users и установки premium для всех пользователей
require('dotenv').config();
const { Pool } = require('pg');
// Создаем пул соединений
const pool = new Pool({
user: process.env.DB_USERNAME,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: parseInt(process.env.DB_PORT || '5432')
});
async function setAllUsersToPremium() {
try {
console.log('Проверяем наличие столбца premium в таблице users...');
const result = await pool.query(`
SELECT EXISTS (
SELECT FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'users'
AND column_name = 'premium'
);
`);
if (!result.rows[0].exists) {
console.log('🔄 Добавляем столбец premium...');
await pool.query(`ALTER TABLE users ADD COLUMN premium BOOLEAN DEFAULT false;`);
console.log('✅ Столбец premium успешно добавлен');
} else {
console.log('✅ Столбец premium уже существует');
}
console.log('Устанавливаем премиум-статус для всех пользователей...');
const updateResult = await pool.query(`
UPDATE users
SET premium = true
WHERE true
RETURNING id, telegram_id, premium
`);
console.log(`✅ Успешно установлен премиум-статус для ${updateResult.rows.length} пользователей:`);
updateResult.rows.forEach(row => {
console.log(`ID: ${row.id.substr(0, 8)}... | Telegram ID: ${row.telegram_id} | Premium: ${row.premium}`);
});
console.log('🎉 Все пользователи теперь имеют премиум-статус!');
} catch (error) {
console.error('Ошибка при установке премиум-статуса:', error);
} finally {
await pool.end();
console.log('Соединение с базой данных закрыто');
}
}
setAllUsersToPremium();