Skip to content

Commit d1f44ce

Browse files
added database_updater and other requirements
1 parent 5513c7b commit d1f44ce

6 files changed

Lines changed: 259 additions & 11 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Python Application
2+
3+
on:
4+
push:
5+
branches: [ "main", "develop" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python 3.11
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install flake8 pytest
28+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
29+
30+
- name: Lint with flake8
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
35+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36+
37+
- name: Test import of main module
38+
run: |
39+
python -c "import pandas, pyodbc; print('Dependencies imported successfully')"

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.csv
2+
__pycache__/
3+
*.pyc
4+
venv/
5+
env/
6+
.env
7+
*.log
8+
.DS_Store
9+
Thumbs.db

CONTRIBUTING.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Contributing to Database Updater
2+
3+
Thank you for your interest in contributing to Database Updater! This document provides guidelines and information for contributors.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you agree to maintain a respectful and inclusive environment for all contributors.
8+
9+
## How to Contribute
10+
11+
### Reporting Bugs
12+
13+
Before creating bug reports, please check existing issues to avoid duplicates. When creating a bug report, include:
14+
15+
- **Clear title**: A brief, descriptive title
16+
- **Environment details**: Python version, OS, SQL Server version
17+
- **Steps to reproduce**: Detailed steps that led to the issue
18+
- **Expected behavior**: What you expected to happen
19+
- **Actual behavior**: What actually happened
20+
- **Error messages**: Full error messages or stack traces
21+
- **Additional context**: Screenshots, configuration files (without sensitive data)
22+
23+
### Suggesting Enhancements
24+
25+
Enhancement suggestions are welcome! Please include:
26+
27+
- **Clear title**: Brief description of the enhancement
28+
- **Detailed description**: Explain the enhancement and its benefits
29+
- **Use cases**: Real-world scenarios where this would be helpful
30+
- **Implementation ideas**: If you have thoughts on how to implement it
31+
32+
### Pull Requests
33+
34+
1. **Fork the repository** and create your branch from `main`
35+
2. **Make your changes** following the coding standards below
36+
3. **Test your changes** thoroughly
37+
4. **Update documentation** if necessary
38+
5. **Commit your changes** with clear, descriptive messages
39+
6. **Submit a pull request** with a clear description
40+
41+
## Development Setup
42+
43+
1. Fork and clone the repository:
44+
```bash
45+
git clone https://github.com/Aditya-Raj-Parashar/data-entry.git
46+
cd database-updater
47+
```
48+
49+
2. Create a virtual environment:
50+
```bash
51+
python -m venv venv
52+
source venv/bin/activate # On Windows: venv\Scripts\activate
53+
```
54+
55+
3. Install dependencies:
56+
```bash
57+
pip install -r requirements.txt
58+
```
59+
60+
## Coding Standards
61+
62+
### Python Style Guide
63+
64+
- Follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guidelines
65+
- Use meaningful variable and function names
66+
- Add docstrings to functions and classes
67+
- Keep functions focused and small
68+
- Use type hints where appropriate
69+
70+
### Code Organization
71+
72+
- Keep the main logic in `database_updater.py`
73+
- Add utility functions to separate modules if needed
74+
- Include error handling for all database operations
75+
- Use logging instead of print statements for debugging
76+
77+
### Documentation
78+
79+
- Update README.md for new features
80+
- Add docstrings to new functions
81+
- Include inline comments for complex logic
82+
- Update requirements.txt if adding new dependencies
83+
84+
## Testing
85+
86+
Currently, the project uses basic import testing. When contributing:
87+
88+
- Test your code with different CSV file formats
89+
- Test with different SQL Server configurations
90+
- Verify error handling works correctly
91+
- Test both Windows and SQL Server authentication methods
92+
93+
## Git Workflow
94+
95+
### Branching Strategy
96+
97+
- `main`: Production-ready code
98+
- `develop`: Integration branch for features
99+
- `feature/feature-name`: New features
100+
- `bugfix/bug-name`: Bug fixes
101+
- `hotfix/issue-name`: Critical fixes
102+
103+
### Commit Messages
104+
105+
Use clear, descriptive commit messages:
106+
107+
```
108+
Add support for custom data types in CSV import
109+
110+
- Allow users to specify column data types
111+
- Add validation for supported SQL Server types
112+
- Update documentation with examples
113+
```
114+
115+
### Pull Request Process
116+
117+
1. Ensure your code follows the style guidelines
118+
2. Update documentation as needed
119+
3. Test your changes thoroughly
120+
4. Write a clear PR description explaining:
121+
- What changes were made
122+
- Why they were made
123+
- How to test them
124+
- Any breaking changes
125+
126+
## Questions?
127+
128+
If you have questions about contributing:
129+
130+
1. Check existing issues and discussions
131+
2. Create a new issue with the "question" label
132+
3. Be specific about what you need help with
133+
134+
## Recognition
135+
136+
Contributors will be recognized in the project documentation. Thank you for helping make Database Updater better!
137+
138+
## License
139+
140+
By contributing to Database Updater, you agree that your contributions will be licensed under the MIT License.

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This Python script updates a Microsoft SQL Server database by creating the datab
2222

2323
1. Clone this repository:
2424
```bash
25-
git clone https://github.com/Aditya-Raj-Parashar/CSV_to_DBO-DATABASE-_Converter.git
25+
git clone https://github.com/Aditya-Raj-Parashar/data-entry.git
2626
cd database-updater
2727
```
2828

@@ -122,13 +122,3 @@ If you encounter issues:
122122

123123
This project is open scourced
124124

125-
126-
127-
git remote add origin https://github.com/Aditya-Raj-Parashar/CSV_to_DBO-DATABASE-_Converter.git
128-
git branch -M main
129-
git push -u origin main
130-
131-
132-
133-
134-
"# CSV_to_DBO-DATABASE-_Converter"

database_updater.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
database_updater.py
3+
4+
This script updates a Microsoft SQL Server database by creating the database and table if they do not exist,
5+
and inserting data from a CSV file into the specified table.
6+
7+
Requirements:
8+
see requirments.txt
9+
10+
Usage:
11+
- Update the database connection parameters below.
12+
- Run the script with Python.
13+
14+
"""
15+
16+
import pandas as pd
17+
import pyodbc
18+
19+
# Database configuration
20+
server = 'localhost' # your server name e.g., 'localhost' or 'server_name\instance_name'
21+
database = 'database_name' # Name of the database you want to create or enter the data
22+
table_name = 'dbo.table_name' # Name of the table where data will be inserted
23+
csv_file_path = 'C:/Users/xyz.csv' # Path to your CSV file
24+
25+
# Create connection string for Windows Authentication
26+
connection_string = f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};DATABASE={database};Trusted_Connection=yes;"
27+
28+
# Connect to the database
29+
try:
30+
conn = pyodbc.connect(connection_string)
31+
cursor = conn.cursor()
32+
33+
# Create database if it doesn't exist
34+
cursor.execute(f"""
35+
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '{database}')
36+
BEGIN
37+
CREATE DATABASE {database}
38+
END
39+
""")
40+
conn.commit()
41+
42+
# Use the specified database
43+
cursor.execute(f"USE {database};")
44+
45+
# Read the CSV file into a DataFrame
46+
df = pd.read_csv(csv_file_path)
47+
48+
# Create table if it doesn't exist
49+
create_table_query = f"""
50+
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{table_name}')
51+
CREATE TABLE {table_name} (
52+
{', '.join([f"{col} NVARCHAR(255)" for col in df.columns])}
53+
);
54+
"""
55+
cursor.execute(create_table_query)
56+
conn.commit()
57+
58+
59+
for index, row in df.iterrows():
60+
insert_query = f"INSERT INTO {table_name} ({', '.join(df.columns)}) VALUES ({', '.join(['?' for _ in row])})"
61+
cursor.execute(insert_query, tuple(row))
62+
63+
conn.commit()
64+
print(f"Data inserted successfully into {table_name}.")
65+
66+
except Exception as e:
67+
print(f"An error occurred: {e}")
68+
finally:
69+
if conn:
70+
conn.close()

requirements.txt

372 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)