wtf db
This commit is contained in:
33
.serena/memories/database_auth_fix_complete.md
Normal file
33
.serena/memories/database_auth_fix_complete.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Database Authentication Issue Fixed
|
||||
|
||||
## Problem
|
||||
- PostgreSQL authentication was failing with error code 28P01 "password authentication failed for user 'quixotic'"
|
||||
- The docker-compose.yml had default password `quixotic123` but .env.docker had different password `GGkM0a6r7pw3F65ZvYbbuOgbt7gO2AoW3JynEk7m9Go=`
|
||||
- Secondary issue: table creation conflicts due to SERIAL sequences being created multiple times
|
||||
|
||||
## Solution
|
||||
1. **Password sync**: Removed postgres container and volume to reset with correct password from .env.docker
|
||||
```bash
|
||||
docker compose down postgres
|
||||
docker volume rm quixotic_postgres-data
|
||||
docker compose up postgres -d
|
||||
```
|
||||
|
||||
2. **Table creation fix**: Modified database.ts to check table existence before creating:
|
||||
- Added proper table existence check using information_schema
|
||||
- Removed `CREATE TABLE IF NOT EXISTS` which wasn't handling SERIAL sequences properly
|
||||
- Added logging for better debugging
|
||||
|
||||
## Commands used
|
||||
```bash
|
||||
docker compose down postgres
|
||||
docker volume rm quixotic_postgres-data
|
||||
docker compose up postgres -d
|
||||
docker compose build quixotic-app
|
||||
docker compose up quixotic-app -d
|
||||
```
|
||||
|
||||
## Result
|
||||
- Database authentication working
|
||||
- No more table creation conflicts
|
||||
- App starts successfully with "Database tables already exist" message
|
||||
@@ -30,8 +30,19 @@ export class Database {
|
||||
|
||||
private async init(): Promise<void> {
|
||||
try {
|
||||
const tablesExist = await this.pool.query(`
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'users'
|
||||
);
|
||||
`);
|
||||
|
||||
if (!tablesExist.rows[0].exists) {
|
||||
console.log('Creating database tables...');
|
||||
|
||||
// Users table
|
||||
await this.pool.query(`CREATE TABLE IF NOT EXISTS users (
|
||||
await this.pool.query(`CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
telegram_id BIGINT UNIQUE NOT NULL,
|
||||
username TEXT,
|
||||
@@ -41,7 +52,7 @@ export class Database {
|
||||
)`);
|
||||
|
||||
// Search history table
|
||||
await this.pool.query(`CREATE TABLE IF NOT EXISTS search_history (
|
||||
await this.pool.query(`CREATE TABLE search_history (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id),
|
||||
query TEXT NOT NULL,
|
||||
@@ -49,7 +60,7 @@ export class Database {
|
||||
)`);
|
||||
|
||||
// Downloaded files table
|
||||
await this.pool.query(`CREATE TABLE IF NOT EXISTS downloads (
|
||||
await this.pool.query(`CREATE TABLE downloads (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id),
|
||||
track_id TEXT NOT NULL,
|
||||
@@ -57,6 +68,11 @@ export class Database {
|
||||
file_path TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)`);
|
||||
|
||||
console.log('Database tables created successfully');
|
||||
} else {
|
||||
console.log('Database tables already exist');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Database initialization error:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user