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 | Interactive mode: shows a multi-select list of all available seeders to run. |
| grow run <NAME> | Run a specific seeder (.ron extension is optional). Example: grow run roles |
| 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
// products: DATA[(OBJECT)],
User: [
(
column_name: "value",
)
],
// Schema qualified tables
"schema.table": [
(
column_name: "value",
)
],
// Repeated data
// products(REPEATED_TIMES): {DATA},
User(4): {
"column_name": "hashed_password_admin{i}",
},
// Repeated data with schemas
// ("schema.table", REPEATED_TIMES): {DATA},
("catalogs.products", 5): {
"name": "{fake(WORD)}",
"description": "{fake(WORD)}",
"price_cents": 10000,
// "price_cents": "{fake(DIGIT)}", // THIS FAKE FEATURE IS NOT SUPPORTED
"currency": "mxn",
},
}-
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_URLis 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_TOKENis 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_TOKENvariable. - 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
fakein column value to create fake data.
Example for fake feature:
{
User(20): {
"role": "client",
"email": "{fake(FREE_EMAIL)}",
// 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)}"
},
}This project is licensed under the MIT License.
