Skip to content

ARabee3/Database-Management-System-DBMS---BashScriptProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„οΈ Bash Database Management System (DBMS)

Made with Bash License: MIT PRs Welcome

A lightweight, file-based database management system built entirely in Bash. This project provides a command-line interface for creating and managing databases and tables with full CRUD operations, data validation, and CSV export capabilities.


πŸ“‹ Table of Contents


✨ Features

πŸ’Ύ Database Operations

  • βœ… Create Database - Create new databases with validation
  • πŸ“‹ List Databases - View all available databases
  • πŸ”Œ Connect to Database - Switch context to work with a specific database
  • πŸ—‘οΈ Delete Database - Remove databases with confirmation prompts

πŸ“Š Table Operations

  • βž• Create Table - Define tables with custom columns and data types
  • πŸ“ List Tables - Display all tables in the current database
  • ❌ Drop Table - Delete tables with confirmation
  • πŸ“₯ Insert Row - Add new records with data validation
  • πŸ” Select Data - Query and display table data (all columns or specific columns)
  • πŸ—‘οΈ Delete Row - Remove records by primary key
  • ✏️ Update Cell - Modify specific cell values
  • πŸ“€ Export to CSV - Export table data to CSV format

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/bash-dbms.git
cd bash-dbms
  1. Make the scripts executable:
chmod +x db.sh table.sh
  1. Run the main script:
./db.sh

🎯 Quick Start

Here's a quick example to get you started:

# Start the DBMS
./db.sh

# Create a database
Select option: 1
Enter Database Name: test_db

# Connect to the database
Select option: 3
Enter Database Name: test_db

# Create a table
Choose option: 1
Enter table name: employees
Number of columns: 3
# Follow the prompts to create your table

# Insert some data
Choose option: 4
# Follow the prompts to insert data

# View your data
Choose option: 5
# Select all columns or specific ones

πŸ“ Project Structure

bash-dbms/
β”œβ”€β”€ db.sh             # Main database management interface
β”œβ”€β”€ table.sh          # Table operations and data management
β”œβ”€β”€ data/             # Directory where databases are stored (auto-created)
β”‚   └── [dbname]/     # Individual database directories
β”‚       β”œβ”€β”€ *.meta    # Table metadata files
β”‚       └── *.data    # Table data files
└── README.md         # Project documentation

🎨 Supported Data Types

Type Description Example
πŸ”’ Int Positive integers only 42, 1000
πŸ“ String Text data (max 30 chars, no :) john_doe, Hello World
πŸ”£ Float Decimal numbers 3.14, 99.99
πŸ“… Date Date in YYYY-MM-DD format 2025-01-04

βœ… Data Validations

The system includes comprehensive validation rules to ensure data integrity:

πŸ—„οΈ Database Name Validation

Rule Description
❌ Non-empty Database name cannot be blank
πŸ“ Length Must be between 3 and 20 characters
πŸ”€ Format Must start with a letter, followed by letters, numbers, or underscores only
πŸ†” Uniqueness Database name must not already exist
πŸ›‘οΈ Path Safety Prevents path traversal attacks by sanitizing input

πŸ“Š Table Name Validation

Rule Description
❌ Non-empty Table name cannot be blank
πŸ”€ Format Must start with a letter, contain only alphanumeric characters and underscores
🚫 Reserved Keywords Cannot use SQL keywords (SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, TABLE, CREATE, DROP)
πŸ†” Uniqueness Table name must not already exist in the database

πŸ“‹ Column Validation

Rule Description
πŸ”‘ Unique Names Column names must be unique within a table
πŸ”€ Format Rules Same naming conventions as tables
🚫 Reserved Keywords Cannot use SQL reserved keywords
πŸ‘‘ Primary Key First column is automatically set as primary key (PK)

🎯 Data Type Validation

πŸ”’ Integer Validation

  • Must match pattern: ^[0-9]+$
  • Only positive integers allowed
  • Example: 123, 456789

πŸ”£ Float Validation

  • Must match pattern: ^[0-9]+([.][0-9]+)?$
  • Decimal point optional
  • Example: 3.14, 100, 99.99

πŸ“ String Validation

  • Maximum 30 characters
  • Cannot contain : character (used as field delimiter)
  • Leading and trailing spaces are automatically trimmed
  • Example: john_doe, Product Name

πŸ“… Date Validation

  • Must match YYYY-MM-DD format
  • Must be a valid calendar date (verified using system date validation)
  • Example: 2025-01-04, 1990-12-31

πŸ”‘ Primary Key Validation

Rule Description
❌ Non-empty PK value cannot be blank
πŸ†” Uniqueness PK values must be unique across all rows
βœ… Type Compliance Must match the datatype defined for the PK column

🧹 Input Sanitization

  • βœ‚οΈ Whitespace Removal - Leading and trailing spaces are automatically removed
  • ❌ Empty Check - All inputs are validated for non-empty values
  • 🚫 Special Characters - Field delimiter (:) is prohibited in string values
  • πŸ”  Case Handling - Reserved keywords are checked case-insensitively

πŸ’‘ Usage Examples

πŸ“₯ Creating a Database

Select option: 1
Enter Database Name: myapp_db
βœ… Success: Database 'myapp_db' created successfully!

πŸ“Š Creating a Table

Choose option: 1
Enter table name: users
Number of columns: 3
Column 1 name: id
Datatype (Int/String/Float/Date): Int
Column 2 name: username
Datatype (Int/String/Float/Date): String
Column 3 name: created_at
Datatype (Int/String/Float/Date): Date
βœ… Table 'users' created successfully!

βž• Inserting Data

Choose option: 4
Table name: users
Enter id (Int): 1
Enter username (String): john_doe
Enter created_at (Date): 2025-01-04
βœ… Row inserted successfully!

πŸ” Selecting Data

Choose option: 5
Enter table name: users
Available columns:
1) id
2) username
3) created_at
Select columns (* for all or e.g. 1,3): *

# Output:
id    username    created_at
1     john_doe    2025-01-04

✏️ Updating a Cell

Choose option: 7
Enter table name: users
Enter PK value: 1
Enter Column number: 2
Enter New value: jane_doe
βœ… Value updated successfully.

πŸ—‘οΈ Deleting a Row

Choose option: 6
Enter table name: users
Enter PK value to delete: 1
βœ… Row with PK '1' deleted successfully.

πŸ“€ Exporting to CSV

Choose option: 8
Enter table name to export: users
βœ… Table 'users' exported to 'users.csv' successfully!

πŸ”’ Security Features

  • πŸ” Permission Control - Database directories are created with 700 permissions
  • πŸ›‘οΈ Path Traversal Prevention - Input sanitization prevents directory traversal attacks
  • ⚠️ Confirmation Prompts - Destructive operations require explicit confirmation
  • βœ”οΈ Script Validation - Checks for required files before execution

βš™οΈ Technical Details

πŸ“„ File Format

Metadata Files (.meta)

column_name:datatype:PK
column_name:datatype

Data Files (.data)

value1:value2:value3
value1:value2:value3

🎨 Color Coding

  • πŸ”΄ Red - Errors and warnings
  • 🟒 Green - Success messages
  • 🟑 Yellow - Warnings and prompts
  • πŸ”΅ Blue - Headers and informational text

πŸ“¦ Requirements

  • Bash 4.0 or higher
  • Standard Unix utilities: awk, sed, grep, cut, paste, column, date
  • Linux or Unix-like operating system

⚠️ Limitations

  • βš™οΈ Single-user system (no concurrent access handling)
  • πŸ”„ No transaction support
  • πŸ” No indexing (linear search for all operations)
  • πŸ’Ύ Limited to local file system storage

πŸš€ Future Enhancements

  • Multi-table JOIN operations
  • WHERE clause filtering in SELECT
  • Backup and restore functionality
  • User authentication and permissions
  • Transaction support with rollback
  • Indexing for faster lookups
  • Support for NULL values
  • Import data from CSV
  • Foreign key constraints
  • Aggregate functions (COUNT, SUM, AVG)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

How to Contribute

  1. 🍴 Fork the repository
  2. πŸ”§ Create your feature branch (git checkout -b feature/AmazingFeature)
  3. βœ… Commit your changes (git commit -m 'Add some AmazingFeature')
  4. πŸ“€ Push to the branch (git push origin feature/AmazingFeature)
  5. πŸŽ‰ Open a Pull Request

πŸ“ License

This project is open source and available under the MIT License.


πŸ‘¨β€πŸ’» Author

Created as an educational project to demonstrate database management concepts using Bash scripting, for ITI Open Source 9-Months Program.

Developed By: Ahmed Rabie & Mokhtar Mohamed


🌟 Show Your Support

Give a ⭐️ if this project helped you!


πŸ“Έ Screenshots

Main Menu

==========================================
       BASH DATABASE MANAGEMENT SYSTEM
==========================================
1) Create Database
2) List Databases
3) Connect to Database
4) Delete Database
5) Exit

Table Operations Menu

1) Create Table
2) List Tables
3) Drop Table
4) Insert Row
5) Select Data
6) Delete Row
7) Update Cell
8) Export To CSV (Bonus)
9) Exit

Made with ❀️ and Bash

Report Bug β€’ Request Feature

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages