Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.77 KB

MIGRATION.md

File metadata and controls

67 lines (51 loc) · 1.77 KB

Database Migration Scripts

These scripts are designed to help you import data into a target database from either a CSV file or another database.

Prerequisites

Before running these scripts, ensure you have the following:

  • Node.js installed on your machine
  • Access to both the source and target databases
  • Necessary permissions to read from the source and write to the target databases

Installation

  1. Clone this repository to your local machine and install dependencies:
git clone <repository-url>
cd sample_userinfo
npm install
npm run generate-all
  1. Update table schema on schema_source.prisma on model User
    • define one by one column name and attributes
    • change "user" on @@map to the user table name

Usage

Import CSV Data (cs_import.js)

  1. Ensure you have a CSV file containing the data you want to import.
  2. Add source.csv file into scripts folder or modify the cs_import.js script to specify the correct file path:
const filePath = '/path/to/source.csv';
  1. Run the script using Node.js:
npm run import:csv

Migrate Data between Databases (db_import.js)

  1. Ensure you have access to both the source and target databases.
  2. Update the SOURCE_DATABASE_URL and DATABASE_URL in .env to reflect the database connection URLs.
# .env
...
SOURCE_DATABASE_URL=mysql://user:[email protected]:3306/userinfo-source
DATABASE_URL=mysql://user:[email protected]:3306/userinfo-target

  1. Modify the columnMappings object to map columns from the source table to the target table. change the value on right based on source column name

  2. Run the script using Node.js:

npm run import:db

Notes

Everytime schema_source.prisma changed, please run again

npm run generate-all