import { Client } from 'pg';
import fs from 'fs';
const envFile = fs.readFileSync('./.env', 'utf-8');
const urlString = envFile.split('\n').find(l => l.startsWith('DATABASE_URL=')).split('=')[1].trim();
const u = new URL(urlString);
u.searchParams.set('sslmode', 'require');

const client = new Client({ connectionString: u.toString() });
client.connect()
  .then(() => client.query('ALTER TABLE lending_pools RENAME COLUMN borrower_interest_rate_pct TO borrower_appreciation_amount; ALTER TABLE loan_applications RENAME COLUMN borrower_interest_rate_pct TO borrower_appreciation_amount;'))
  .then(() => { console.log('Renamed'); client.end(); })
  .catch(e => { console.error(e); client.end(); });
