NodeJS Inverse Seed Generator is a really handy tool to have in a perfect development environment.

Sometimes you may wanna write the existing data of the database tables, to seed files for later usage. For example you might have some default basic data in a table and you might wanna keep them in the project to inject them by default to the database when the project is deployed on a separate environment. (Eg: Staging server to Live server).

In a scenario like these, what you normally would do is just export the current database dump to the new environment and connect the project to the database. But there can be more smarter ways of doing it right ?

That’s where Inverse Seeds comes to the picture.

Basically what Inverse Seeds or iSeeds means is, it inverting the typical Seeding functionality. So, instead of Running seeders and populating tables, you can create seeds with existing table data.

This NodeJS Inverse Seed Generator is an NPM Package that allows to generate inverse seeds when using Sequelize ORM.

Sequeliseed - NodeJS Inverse Seeds Generator

What you basically want to do is, first install the package on your NodeJS project.

$ npm i sequeliseed

Then you can generate as many as seeders based on the existing table data. Sequeliseed has its own CLI. So, it’s super easy to run commands and generate the seeds.

Generate a seeder file from a table.

$ npx sequeliseed generate table_name

Generate multiple seeders from multiple tables at once.

You can add as many as tables separated by a space.

$ npx sequeliseed generate table1_name table2_name table3_name

Manual Configurations

You can specify the environment that you’re running this seeds generator. This is important because, the environment is specified in Sequelize config.json file. So, to connect to the correct database,make sure you specify the correct database.

In some cases, the default files and folders structure of Sequelize ORM is altered by developers for their convenience. In those cases, Sequeliseed might not be able to find the correct Sequelize config.json file which listed all the database configurations. So in those cases, you can can generate seeds by adding configurations manually.

$ npx sequeliseed generate table_name --config

This will prompt for some questions like what’s the Database type, Host, Username, Password and Database name.

Sequeliseed - NodeJS Inverse Seeds Generator

You can simply put correct values and it will generate seeds for you.

That’s it. See it’s that easy. You can find more details on Sequeliseed documentation or this article I wrote few days back.

Sequeliseed currently supports all the database types supported by Sequelize ORM.

That’s for stopping by. Leave a comment if you find this article useful! Thanks!