Grow Seeder CLI is a command line tool written in Rust to manage database seeders. It allows to generate, list and run seeders defined in RON format for LibSQL, PostgreSQL, MySQL and SQLite compatible databases. Automatically detects the database type through the DATABASE_URL
environment variable.
- Environment variables:
DATABASE_URL
: Database connection URL.TURSO_AUTH_TOKEN
(only for LibSQL/Turso databases).
cargo install grow-rs
# or
cargo install --git https://github.com/Wilovy09/Grow-rs
Commands | Functions |
---|---|
grow init | Creates a seeders/ folder in the current directory to store seeders. |
grow new <NAME> | Creates a new .ron file inside the seeders/ folder. The file name will be <NAME>.ron . |
grow list | Displays a list of all available seeders in the seeders/ folder. |
grow run [NAME.ron] | Run the seeder. If no file is specified, it will run all seeders in alphabetical order. |
Feature | Description |
---|---|
default |
Install libsql , sqlx databases and fake support. |
fake |
Enable fake support |
libsql |
Install only libsql support. |
sqlx |
Install only sqlx databases support. |
A seeder file in .ron
format could have the following content:
Note
If the ID is generated automatically by the db, it is not necessary to enter it in the seeder.
{
// Static data
// TABLE_NAME: DATA[],
User: [
{
"role": "Admin",
"email": "admin@example.com",
"password": "hashed_password_admin",
"created_at": "2024-12-22 12:00:00",
"updated_at": "2024-12-22 12:00:00"
},
]
// Repeated data
// TABLE_NAME(REPEATED_TIMES): DATA,
User(4): [
{
"role": "client",
"email": "{fake(EMAIL_PT_BR)}",
// Templating have `i` to know the iteration
"password": "hashed_password_admin{i}",
"created_at": "2024-12-22 12:00:{mul_u32(i, 10)}",
"updated_at": "2024-12-22 12:00:{mul_u32(i, 20)}"
},
]
}
-
PostgresSQL, MySQL, SQLite (SQLx Support):
DATABASE_URL=sqlite://DB_NAME
- This line configures the database URL for SQLite. The format sqlite://DB_NAME indicates that SQLite is being used, and DB_NAME is the name of the database.
-
libsql (TURSO)
DATABASE_URL=libsql://DB_NAME.turso.io TURSO_AUTH_TOKEN=eyJhbGciWJhNGRjIn0.igV6yDaKTuDKM7_5J-UWGOftULBg
- Here,
DATABASE_URL
is configured to use libsql, which is a SQLite-compatible database with additional features like cloud synchronization. DB_NAME.turso.io is the URL of the database on Turso. TURSO_AUTH_TOKEN
is an authentication token required to access the database on Turso.
- Here,
-
Dry-run (Simulation)
DATABASE_URL=mock://DB_NAME
- This configuration is used to perform a simulation or "dry-run." Instead of connecting to a real database, a mock database is used to test commands without affecting real data.
On operating systems like Windows, paths (file directories) are traditionally written using the backslash (). However, in the context of software development, especially when working with cross-platform tools and languages, it is common to use the forward slash (/) instead of the backslash.
- Reason: The forward slash (/) is the standard on Unix systems (like Linux and macOS) and is widely supported on Windows. Using / ensures that the code is compatible across different operating systems.
- Example:
- Instead of writing:
DATABASE_URL=sqlite://C:\Users\User\Documents\DB_NAME
- You should write:
DATABASE_URL=sqlite://C:/Users/User/Documents/DB_NAME
This approach avoids compatibility issues and errors when moving code between different operating systems.
Grow Seeder CLI is compatible with:
Note
Required on all DATABASE_URL
in your .env
- LibSQL: Requires the
TURSO_AUTH_TOKEN
variable. - PostgreSQL
- MySQL
- SQLite
The CLI automatically detects the database type via DATABASE_URL
and handles the connection appropriately.
- Create a library to run seeder in the code and not with CLI
- Add cargo features to CLI.
- Add
fake
in column value to create fake data.
Example for fake
feature:
{
// Generate 20 fake users
User(20): [
{
"role": "CLIENT",
"email": "{fake(EMAIL)}",
"password": "{fake(PASSWORD)}",
// Multi-language support
"first_name": "{fake(FIRST_NAME_FR_FR)}",
},
]
}
This project is licensed under the MIT License.