These scripts are designed to help you import data into a target database from either a CSV file or another database.
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
- Clone this repository to your local machine and install dependencies:
git clone <repository-url>
cd sample_userinfo
npm install
npm run generate-all
- 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
- Ensure you have a CSV file containing the data you want to import.
- 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';
- Run the script using Node.js:
npm run import:csv
- Ensure you have access to both the source and target databases.
- 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
-
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
-
Run the script using Node.js:
npm run import:db
Everytime schema_source.prisma
changed, please run again
npm run generate-all