Giter VIP home page Giter VIP logo

csv-uploader's Introduction

This is a migration tool, responsible for uploading massive CSVs to a centralised database. The database can be accessed remotely by teams with the right set of credentials. This repository contains the database physical schema creation, and uploading passed CSV files to appropriate tables.

Database Schema

database_schema

For more details on the schema see here.

Development Environment Setup

1. Clone the Repository

$ git clone https://github.com/s-bose7/csv-uploader.git

2. Project Setup

Navigate to the project directory:

$ cd csv-uploader

Create and activate a virtual environment using your preferred tool (e.g., venv).

$ python3 -m venv gp-db-uploader
$ source gp-db-uploader/bin/activate # unix

Install dependencies listed in requirements.txt:

$ pip install -r requirements.txt

Create a data directory to store your CSV files for upload.

$ mkdir data  # UNIX

Create the migration environment:

$ alembic init migrations # This will create a dir migrations in project root with an alembic.ini file

3. Environment Variables (.env)

Create a .env file in the project root for environment variables:

$ touch .env # UNIX

Populate the .env file with the following variables, replacing the placeholders with your actual credentials:

DEV_DB_USER=postgres
DEV_DB_PASSWORD=your_development_password
DEV_DB_HOST=localhost
DEV_DB_PORT=5432
DEV_DB_NAME=your_development_database_name

PROD_DB_USER=your_production_username
PROD_DB_PASSWORD=your_production_password
PROD_DB_HOST=your_production_database_host
PROD_DB_PORT=5432
PROD_DB_NAME=your_production_database_name

Important:

Obtain production credentials from your heroku-postgres settings. Never store production credentials in version control (e.g., Git).

4. Starting the Database container (Development Only)

Refer to this separate guide for instructions on starting the database container in a development environment.

Using the Tool

1. Running Migrations:

run_migrations.py handles database schema changes through Alembic migrations. Execute this first:

python3 run_migrations.py -production -new  # Use '-development' for development

-new flag is to indicate that there's been some changes in the original database schema, so alembic needs to create new migrations accordingly. So only pass this flag if you changed the original schema otherwise leave blank.

2. Uploading Data:

main.py uploads data from your CSV files. Run it only after migrations:

python3 main.py -production  # Use '-development' for development

Additional Notes:

The -production flag is used for production environment. Use -development for local development.
The project uses Alembic for migrations. Refer to the official documentation for advanced usage.

Data Integrity checks

Data integrity checks are important to verify the core database insertion logic. Refer here to see the kinds of checks being performed after inserting data.

Development checklist

  • Create database schema
  • Add configurations
  • Create the migrations
  • Read and validate data
  • Make insertions
  • Add indexes to tables
  • Add logging
  • Deploy to heroku
  • Batch insertions for better performance.

csv-uploader's People

Contributors

s-bose7 avatar

Stargazers

Rajendra Agrawal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.