Sequelize-cli how to create seed files from an existing database?
Asked Answered
S

2

9

Issue:

In order to start in a clean environment for developing stuff for a web app I would appreciate to be able to retrieve some data from an existing DB (let say the 10 first lines of every tables) in order to create a sequelize seed file per table. It will then be possible to seed an empty DB with these data into the corresponding models and migrations.

I have found the tool named sequelize-auto which seems to work fine to generate a model file from an exsting DB (beware of not already having for example a uses.js model ; it will be overwritten !) : https://github.com/sequelize/sequelize-auto.

This tool will create a model file, but neither a migration or a seed file.

Question:

Is there a way to build a seed file from an existing database?

Swallowtailed answered 4/2, 2018 at 13:38 Comment(1)
did you find a way?Awhile
I
0

Found this cool module you can create (dump) seed with command

npx sequeliseed generate table_name --config

https://www.npmjs.com/package/sequeliseed

Isomerize answered 6/9, 2022 at 1:45 Comment(1)
fyi : I'couldn succeded somehow getting errors relation "tablename" does not existLincoln
L
0

You may find some library to do this job, but in my situation, the use case was to insert data from the user interface and then generate the seed for it (instead of doing it one by one by hand). So, I've prepared a custom script for it.

The script parses your SQL dump and generates Sequelize seed files. All you need to do is paste the generated SQL dump from your database (in this example, it was generated using pgAdmin4), save it as dump.sql, and then run the main.py. The output should be located in the folder with the same name.

Edit 50069724/how-to-add-multiple-material-ui-palette-colors

This script was tested to work just for the output from pgAdmin4 (Right Click > Backup).

Leslileslie answered 28/8, 2023 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.