This repository provides a complete solution for transferring and synchronizing data between DEV and PROD PostgreSQL databases. The solution includes Python scripts for creating databases, inserting sample data, and transferring data from DEV to PROD.
- PostgreSQL installed on your machine.
- Python 3.x installed with the required packages listed in
requirements.txt
.
-
Clone the repository:
git clone https://github.com/SergeiVorobev/db-transfer-solution.git cd db-transfer-solution
-
Create a virtual environment:
For macOS and Linux:
python3 -m venv venv source venv/bin/activate
For Windows:
python -m venv venv .\venv\Scripts\activate
-
Install required Python packages:
pip install -r requirements.txt
-
Set up the databases:
- Run the
create_databases_and_tables.py
script to create the necessary databases and tables:
python3 scripts/create_databases_and_tables.py
- Run the
-
Insert sample data into databases:
- Run the
insert_sample_data.py
script to populate the DEV and PROD databases with sample data from the JSON files in thesample_data
directory:
python3 scripts/insert_sample_data.py
- Run the
-
Transfer and synchronize data from DEV to PROD:
- Run the
data_transfer.py
script to transfer and synchronize data from the DEV database to the PROD database:
python3 scripts/data_transfer.py
- Run the
-
Ensure the
.env
file is properly set up with the correct PostgreSQL credentials:DB_HOST=your_db_host DB_PORT=your_db_port DB_USER=your_db_user DB_PASSWORD=your_db_password DB_DEV_NAME=your_dev_db_name DB_PROD_NAME=your_prod_db_name