Database added

This commit is contained in:
2026-03-20 11:21:04 -04:00
parent 2dec1f1f93
commit 821cf379a9
4 changed files with 263 additions and 28 deletions

31
migrate.js Normal file
View File

@ -0,0 +1,31 @@
import fs from 'fs';
import pg from 'pg';
const { Pool } = pg;
const pool = new Pool({
connectionString: "postgresql://app_user:Al5eVT1SJ7i4UHmSZr1F@204.168.129.249:5432/app_data",
ssl: false
});
const quotes = JSON.parse(fs.readFileSync('quotes.json', 'utf8'));
async function migrate() {
await pool.query(`
CREATE TABLE IF NOT EXISTS quotes (
id SERIAL PRIMARY KEY,
quote_id VARCHAR(255) UNIQUE NOT NULL,
data JSONB NOT NULL
)
`);
for (const q of quotes) {
await pool.query(
'INSERT INTO quotes (quote_id, data) VALUES ($1, $2) ON CONFLICT (quote_id) DO UPDATE SET data = $2',
[String(q.id), q]
);
}
console.log(`Successfully migrated ${quotes.length} quotes to your new production database!`);
process.exit(0);
}
migrate().catch(console.error);