https://github.com/tameronline/postgres-admin-tools
Utility scripts for managing PostgreSQL databases and tables via SQLAlchemy and psycopg2.
https://github.com/tameronline/postgres-admin-tools
Last synced: 9 months ago
JSON representation
Utility scripts for managing PostgreSQL databases and tables via SQLAlchemy and psycopg2.
- Host: GitHub
- URL: https://github.com/tameronline/postgres-admin-tools
- Owner: TamerOnLine
- License: mit
- Created: 2025-06-13T23:09:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-13T23:46:01.000Z (about 1 year ago)
- Last Synced: 2025-06-14T00:27:42.645Z (about 1 year ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ ๏ธ PostgreSQL Admin Tools

A lightweight admin interface and CLI toolkit for PostgreSQL, built with **Flask**, **SQLAlchemy**, and **psycopg2**.
> Manage your databases and tables with ease โ via web or terminal.
---
## ๐ฅ Clone the Repository
To get started, clone this repository to your local machine using Git:
```bash
git clone https://github.com/TamerOnLine/postgres-admin-tools.git
cd postgres-admin-tools
```
- Make sure you have Git installed.
- [You can download it from](https://git-scm.com).
๐ธ Cloning the repository via Git command line
---
## ๐ฆ Features
- ๐ Secure user system with Flask-Login (default admin: `admin/12345`)
- โ๏ธ Create or drop PostgreSQL databases
- ๐งฑ Manage tables (create / migrate / drop) via SQLAlchemy
- ๐พ Full database backup & restore using `pg_dump` / `psql`
- ๐งฉ Easy environment config via `.env` file
- ๐ Flask-based web UI ready out of the box
---
## ๐ฌ Demo
๐ฝ๏ธ Quick demo of the PostgreSQL Admin Tools in action
---
## ๐ง Tech Stack
| Technology | Description |
|----------------|-------------------------------------|
| Python | Core programming language |
| PostgreSQL | Relational database engine |
| SQLAlchemy | ORM for database modeling |
| psycopg2 | PostgreSQL driver for Python |
| python-dotenv | Load `.env` variables into runtime |
---
## ๐งฑ Project Structure
```
postgres-admin-tools/
โโโ myapp.py # Flask app with login & DB panel
โโโ requirements.txt
โโโ LICENSE
โโโ README.md
โโโ models/
โโโ models_definitions.py # SQLAlchemy models
โโโ db_postgres/
โโโ create.py # Create DB if not exists
โโโ drop.py # Drop DB (safe disconnect)
โโโ drop_table.py # Drop individual/all tables
โโโ manage_tables.py # Schema updates
โโโ BACKUP.py # Backup to SQL file
โโโ RESTORE.py # Restore from backup
โโโ db_config.py # Load from .env
```
---
## โ๏ธ Environment Setup
Create a `.env` file in the root directory:
```env
DATABASE_URL=postgresql://user:password@localhost:5432/your_db
SECRET_KEY=your_secret_here
```
---
## ๐ Quick Start
### 1. Create Virtual Environment
```bash
# Windows
py -3.12 -m venv venv
.\venv\Scripts\Activate
```
๐ธ Virtual environment activated successfully
---
```bash
# macOS / Linux
python3 -m venv venv
source venv/bin/activate
```
---
### Install Dependencies
```bash
pip install -r requirements.txt
```
๐ธ Installing dependencies using pip
---
### Create Database
```bash
py .\models\db_postgres\create.py
```
๐ธ Creating PostgreSQL database
---
### Drop Database
```bash
py .\models\db_postgres\drop.py
```
๐ธ Dropping the database safely
---
### Drop Tables
```bash
py .\models\db_postgres\drop_table.py
```
๐ธ Dropping selected or all tables
---
### Manage Tables
```bash
py .\models\db_postgres\manage_tables.py
```
๐ธ CLI interface to manage tables (create or sync)
---
### Backup Database
```bash
py .\models\db_postgres\BACKUP.py
```
๐ธ Generating SQL backup file using `pg_dump`
---
### Restore Database
```bash
py .\models\db_postgres\RESTORE.py
```
๐ธ Restoring database from SQL file
---
## ๐ก๏ธ User System
The system automatically creates a **default admin user** on first run if no user with username `admin` is found.
- **Username**: `admin`
- **Password**: `12345`
To manually trigger this, run the following command:
```bash
py .\models\models_definitions.py
```
You can modify this logic in [`models/models_definitions.py`](models/models_definitions.py).
๐ธ Creating default admin user if not exists
---
## ๐งช SQLite Test Mode
If `DATABASE_URL` is not set in the `.env`, the system defaults to SQLite (`sqlite:///test.db`) for quick testing.
> Note: Scripts like `create.py`, `BACKUP.py`, etc., require PostgreSQL and do not support SQLite.
---
## ๐ CLI Command Summary
| Operation | Script | Mode |
|----------------------|---------------------|-----------------|
| ๐๏ธ Create Database | `create.py` | CLI |
| โ Drop Database | `drop.py` | CLI |
| ๐งน Drop Tables | `drop_table.py` | Interactive CLI |
| ๐งฉ Manage Tables | `manage_tables.py` | Interactive CLI |
| ๐พ Backup Database | `BACKUP.py` | CLI |
| โป๏ธ Restore from Backup | `RESTORE.py` | Interactive CLI |
---
## ๐ License
This project is licensed under the MIT License.
See the [LICENSE](./LICENSE) file for details.
---
## ๐จโ๐ป Author
**Tamer Hamad Faour**
GitHub: [@TamerOnLine](https://github.com/TamerOnLine)