The goal of this assignment is to build a simple command-line user registration system using Python and MySQL. You will gain hands-on experience connecting to a database, executing SQL CRUD operations (Create, Read, Update, Delete), generating synthetic data, and designing a user-friendly command-line interface.
Problem set description document: Document Link.
Run the Interactive Menu
python3 main.pyThis will launch the interactive CLI menu for managing users.
If you're interested in understanding the setup and testing process step-by-step, continue reading below.
✅ Note: The database is already configured. The steps below are for demonstration purposes only — you do NOT need to repeat them.
🐳 1. Start MySQL Using Docker
setup db:
docker run -d \
--name mysql-server \
-e MYSQL_ROOT_PASSWORD=root123 \
-e MYSQL_DATABASE=user_registration \
-p 3306:3306 \
mysql:8.0- verify
docker ps 📦 2. Install Dependencies
pip install mysql-connector-python PyYAML Faker rich
and
pip install bcrypt- Note: this is only to test classes one by one, you also do not need to do it unless you want to to make sure everything is fine (it's already tested)
Test db_connection.py :
python3 -c "from db_connection import get_connection, close_connection; conn = get_connection(); close_connection(conn) if conn else None"create db and tables:
python3 create_database_and_table.pycreate first user:
Test create user with invalid user name
python3 -c "from create_user import create_user; create_user('nora', 'test@test.com', 'pass123', 'bos', 'Company', 'Dev')"Read all users
python3 read_users.pyUpdate user interactive:
python3 update_user.pyor not interactive:
python3 -c "from update_user import update_user_password; update_user_password('nora', 'newpassword123')"delete user (interactive)
python3 delete_user.pynow ill create another user just to continue working (not interactive)
python3 -c "from create_user import create_user; create_user('ali_smith', 'ali@example.com', 'password456', 'San Francisco', 'Tech Solutions', 'Data Scientist')"Now let's create synthatic 1000 user :
python3 populate_users.pylet's read them :
python3 read_users.pyand here let's count them
docker exec mysql-server mysql -uroot -proot123 user_registration -e "SELECT COUNT(*) as total_users FROM users;"