A Python toolkit for PostgreSQL administration with database creation, deletion, schema management, backup, and restore utilities. The repository also contains a minimal Flask application foundation built with Flask-SQLAlchemy and Flask-Login.
Important
This is a development and reference project, not a production-ready administration panel. Authentication routes and authorization controls are not yet implemented. Do not expose the Flask application to the public internet.
- Validated PostgreSQL configuration through environment variables
- Database creation with safely quoted identifiers
- Explicitly confirmed database deletion
- SQL backup with
pg_dump - Confirmed restore with
psql - Table creation, synchronization, and deletion utilities
- SQLAlchemy user model with password hashing
- Flask application factory
- GitHub Actions workflow
The project intentionally has:
- no default administrator account
- no hardcoded administrator password
- no fallback Flask secret key
- no fallback database username or password
- Debug mode disabled unless explicitly enabled
- database credentials scoped to backup and restore subprocesses
- stronger confirmation for destructive operations
- Python 3.10+
- PostgreSQL client tools
pg_dumpandpsqlavailable on PATH, or installed in a supported Windows PostgreSQL location
git clone https://github.com/TamerOnLine/postgres-admin-tools.git
cd postgres-admin-toolspython -m venv .venvActivate it:
# Linux or macOS
source .venv/bin/activate
# Windows PowerShell
.\.venv\Scripts\Activate.ps1pip install -r requirements.txtcp .env.example .envReplace every placeholder in .env. Never commit the resulting .env file.
You may configure PostgreSQL with one complete URL:
DATABASE_URL=postgresql://user:password@localhost:5432/database_nameOr with individual variables:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=database_name
DB_USER=database_user
DB_PASSWORD=use-a-strong-passwordGenerate a Flask secret:
python -c "import secrets; print(secrets.token_hex(32))"Store the result as SECRET_KEY in .env.
python models/db_postgres/create.pypython models/db_postgres/manage_tables.pypython models/db_postgres/BACKUP.pyBackups are stored in the ignored local backups/ directory.
python models/db_postgres/RESTORE.pyThe command requires typing RESTORE before applying the selected SQL file.
python models/db_postgres/drop.pyThe command requires typing the exact configured database name before deletion.
python myapp.pyThis creates the database tables and starts the minimal application. It does not provide a completed login or administration interface.
postgres-admin-tools/
├── .env.example
├── .github/workflows/
├── models/
│ ├── models_definitions.py
│ └── db_postgres/
│ ├── BACKUP.py
│ ├── RESTORE.py
│ ├── create.py
│ ├── db_config.py
│ ├── drop.py
│ ├── drop_table.py
│ └── manage_tables.py
├── myapp.py
├── requirements.txt
└── README.md
Before production use, add and test:
- login, logout, and administrator provisioning workflows
- route-level authorization
- CSRF protection for web forms
- secure session-cookie settings
- dependency version locking and automated security updates
- automated tests for destructive database operations
- structured audit logging
- deployment behind TLS and a production WSGI server
Released under the MIT License. See LICENSE.