4.4 KiB
Postgres Web Admin Panel
A modern web-based admin interface for PostgreSQL with Material UI.
Features
- 🔐 User/password authentication
- 💎 Material UI design
- 📊 View database tables
- 🔍 SQL query interface (SELECT only for security)
- 📋 Table data viewer with pagination
- 🐳 Docker support
- 📦 GitHub Container Registry (GHCR) integration
Quick Start
1. Setup Database
First, ensure your database is running and migrations are applied:
npm run db:migrate
2. Create Admin User
Create an admin user for logging into the admin panel:
npm run db:seed-admin
This creates a default admin user:
- Username: admin
- Password: admin123
You can customize these credentials by setting environment variables:
ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword npm run db:seed-admin
3. Access the Admin Panel
Start the development server:
npm run dev
Navigate to: http://localhost:3000/admin/login
Docker Deployment
The project includes an all-in-one Docker image that contains both PostgreSQL and the Next.js application, making deployment simple and straightforward.
Build Docker Image
docker build -t postgres-admin .
Run with Docker (All-in-One)
The simplest way to run the application is using the all-in-one image:
docker run -p 3000:3000 -p 5432:5432 \
-e JWT_SECRET="your-secret-key" \
-e ADMIN_USERNAME="admin" \
-e ADMIN_PASSWORD="admin123" \
postgres-admin
The container will:
- Start PostgreSQL automatically
- Run database migrations
- Create the admin user
- Start the Next.js application
Access the admin panel at: http://localhost:3000/admin/login
Using Docker Compose
The easiest way to run the application:
docker-compose up
This will:
- Build the all-in-one image
- Start PostgreSQL and Next.js in the same container
- Expose ports 3000 (web) and 5432 (database)
- Create a persistent volume for PostgreSQL data
- Automatically create an admin user
Access the admin panel at: http://localhost:3000/admin/login
Default credentials:
- Username: admin
- Password: admin123
Multi-Container Setup (Optional)
If you prefer to run PostgreSQL in a separate container, create this docker-compose.yml:
version: '3.8'
services:
postgres:
image: postgres:16
environment:
POSTGRES_DB: mydb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
admin:
build: .
ports:
- '3000:3000'
environment:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/mydb
JWT_SECRET: your-secret-key-here
depends_on:
- postgres
volumes:
postgres_data:
Run:
docker-compose up
GitHub Container Registry (GHCR)
The project automatically builds and publishes Docker images to GitHub Container Registry when you push to the main branch or create tags.
Pull from GHCR
docker pull ghcr.io/johndoe6345789/postgres:latest
Run from GHCR
docker run -p 3000:3000 \
-e DATABASE_URL="your-database-url" \
-e JWT_SECRET="your-secret-key" \
ghcr.io/johndoe6345789/postgres:latest
Environment Variables
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
JWT_SECRET |
Secret key for JWT tokens | your-secret-key-change-in-production |
ADMIN_USERNAME |
Initial admin username | admin |
ADMIN_PASSWORD |
Initial admin password | admin123 |
Security
- Only SELECT queries are allowed in the SQL query interface
- Password authentication with bcrypt hashing
- JWT-based session management
- HTTP-only cookies for session tokens
- Protected API routes requiring authentication
API Routes
POST /api/admin/login- User loginPOST /api/admin/logout- User logoutGET /api/admin/tables- List all database tablesPOST /api/admin/query- Execute SQL query (SELECT only)
Production Deployment
- Set strong passwords for admin users
- Use a secure JWT_SECRET
- Enable HTTPS
- Configure proper CORS settings
- Set up database backups
- Monitor logs and errors
Development
# Install dependencies
npm install
# Run migrations
npm run db:migrate
# Create admin user
npm run db:seed-admin
# Start dev server
npm run dev
License
MIT