seed-sql
v1.0.3
Published
seed-sql is a command-line tool designed to automate the process of populating MySQL databases with realistic mock data. Unlike other data seeding tools that require extensive configuration, Seed-SQL simplifies the process by detecting the database schema
Downloads
7
Maintainers
Readme
seed-sql
seed-sql is a command-line tool designed to automate the process of populating MySQL databases with realistic mock data. Unlike other data seeding tools that require extensive configuration, Seed-SQL simplifies the process by detecting the database schema and foreign keys automatically, needing only the table name to generate and insert mock data. This reduces setup time and ensures the mock data is as close to real-world data as possible.
Installation
You need to install this tool globally via npm:
npm install -g seed-sqlOnce installed, you can use the seed-sql commands in your project directory.
Configuration
After installing seed-sql, you must execute the seed-sql --init command in your project directory.
When you run this command, a .seed-sql.config.json file will be created in your project directory with your database credentials. This file is used for connecting to your database.
The .seed-sql.config.json file contains the following keys:
gemini_api_key : Your gemini api key.
host: The host address of your database (default: localhost).
port: The port for the database (default: 3306).
username: The username for the database.
password: The password for the database.
database: The name of the database to connect to.
connectionLimit: The connection limit for the pool (default: 10)Commands
--init : This command initializes the configuration for the database connection.
seed-sql --initIt will prompt you to enter your database details like host, username, password, and database name. This will create a .seed-sql.config.json file in your project directory.
Example of .mockgen.config.json:
{
"gemini_api_key": "<api-key>",
"host": "localhost",
"port": "3306",
"username": "root",
"password": "<password>",
"database": "my database",
"connectionLimit": "10"
}--status : Checks the status of the database connection.
seed-sql --statusThis will check if the connection to the database is successful and show whether the database is online or offline.
--tables : Fetches the list of tables from the configured database.
seed-sql --tablesThis command will retrieve the list of tables from your MySQL database.
--generate : Generate mock data for the specified tables.
seed-sql --generateThis will generate realistic mock data for your tables and insert it into your MySQL database. It uses AI to ensure the generated data is unique and realistic.
The Schema and the map of foreign keys are sent to the generator function and the data is generated accordingly.
The foreign key map looks like this:
{
fk1 : [fkVal1,fkVal2,fkVal3],
fk2 : [fk2Val1,fk2Val2,fk2Val3]
}Where fk1 and fk2 are the field name which are foreign keys and the array is of the value associated with them respectively.
You can add optional --prompt flag with the --generate and then add your prompt to get controlled data.
Example:
seed-sql --generate --prompt "the test id in the data should be the second one the test ids in foreign key map and randomize other foregin keys value among given."
Dependencies
mysql2 : MySQL driver for Node.js.
chalk : For styling output in the terminal.
inquirer : For user prompts and interactions.
yargs : For parsing command-line arguments.
@google/genai : For generating mock data using AI (Google Gemini AI).
seed-sql is built with care to help developers quickly generate and seed mock data into MySQL databases, making development and testing easier.
