TideORM CLI
A comprehensive command-line interface for TideORM - A powerful Rust ORM.
Installation
Install globally:
Quick Start
# Initialize a new TideORM project
# Generate a model with fields, relations, and more
# Run migrations (`tideorm migrate` on its own does the same thing)
# Seed the database
Configuration
TideORM CLI uses a tideorm.toml configuration file:
[]
= "my-tideorm-project"
= "development"
[]
= "postgres"
= "localhost"
= 5432
= "myapp"
= "postgres"
= "password"
# Or use a connection URL:
# url = "postgres://postgres:password@localhost/myapp"
[]
= "src/models"
= "src/migrations"
= "src/seeders"
= "src/factories"
= "src/config.rs"
[]
= "_migrations"
= true
[]
= true
= false
= false
= "id"
= "i64"
Commands
Migration Commands
# Run all pending migrations
# Run migrations with options
# Generate a new migration
# Migration up/down
# Redo migrations
# Fresh migrations (drop all tables and re-run)
# Without --force this asks for confirmation and fails if it cannot prompt.
# Reset migrations (rollback all)
# Refresh migrations (reset + migrate)
# Reconcile the migration ledger without running any SQL
# MySQL and MariaDB commit DDL implicitly, so a migration whose schema change
# succeeded but whose ledger row was never written leaves later runs stuck on
# "table already exists". These repair the ledger by hand.
# View migration status
Rollback order follows the order migrations were applied, not their version strings, so a migration merged in from a long-lived branch is rolled back in the order it actually ran.
Model Generation
The make model command is the most powerful generator, supporting:
# Basic model
# Model with fields
# Field types:
# string, text, i32, i64, f32, f64, bool, datetime, date, time,
# uuid, json, jsonb, decimal, bytes,
# int_array, bigint_array, text_array, bool_array, float_array, json_array
# (array types are PostgreSQL-only; on SQLite and MySQL store lists as json)
# (SQL spellings are accepted as aliases: varchar, tinyint, smallint, int, integer,
# bigint, float, double, boolean, timestamp, blob, binary, integer_array,
# string_array, boolean_array)
# Field modifiers: nullable, unique, indexed, primary_key, auto_increment, default=value
# Model with relations
# Model with translatable fields
# Model with attachments
# Model with indexes
# Model with nullable fields
# Enable special features
# Generate with migration, seeder and factory
# Write the model somewhere other than the configured [paths] models directory.
# A companion --seeder/--factory generated in the same run imports the model from
# wherever --output put it.
# Full example
Other Generators
# Generate a migration
# Generate a seeder (--count sets how many records the generated seeder creates)
# Generate a factory
# Every `make` generator accepts --output to choose the target directory
--output defaults to the same value as the matching [paths] entry
(src/migrations, src/seeders, src/factories, src/models). Left alone, the
configured [paths] directory wins; passing anything else overrides it for that run
only. The generated file and the mod.rs next to it both go to the chosen directory,
so remember to declare that directory as a module in your crate.
Moving a seeder or a factory does not move the model it imports: the generated
use crate::.. path is still derived from [paths] models.
Database Commands
# Run every seeder that has not run yet (see "Seeding" below)
# Drop all tables, re-run migrations and re-seed
# Show database connection status
# Initialize TideORM metadata tables
# Create the database
# Drop the database
# Wipe all tables - this DROPS every table, schema included; it is not a TRUNCATE.
# `migrate fresh` relies on those drop semantics to rebuild from the migrations.
# Show table information
Destructive commands (db drop, db wipe, db fresh, migrate fresh) prompt for
confirmation unless --force is given. A run that cannot prompt - no terminal, or
CI / TIDEORM_NONINTERACTIVE set - fails with a non-zero exit rather than
reporting a cancellation as success, so pass --force in scripts and CI.
Seeding
Seeders are Rust code in your project, so the CLI runs them through a small binary
the project owns, named after its package: for my-app, tideorm db seed is
cargo run --bin my-app-seed, with DATABASE_URL set to the database the CLI resolved.
Without --seeder it runs every seeder in seeders::all() that has not run yet -
TideORM records them in the _seeds table and orders them by priority() and
depends_on(). --seeder=UserSeeder, or --seeder=User, runs that one seeder again.
db fresh, migrate fresh --seed and migrate refresh --seed check for the runner,
and for the seeder --seeder names, before dropping or resetting anything.
tideorm init lays a new project out for this - the modules live in src/lib.rs, so
both src/main.rs and src/bin/my-app-seed.rs can use them, and default-run keeps
plain cargo run on your app - and tideorm make seeder registers each new seeder in
seeders::all(). To add seeding to an existing project:
-
Move the module declarations from
src/main.rsintosrc/lib.rs(pub mod config; pub mod models; pub mod seeders; ...), refer to them fromsrc/main.rsasmy_app::config, and adddefault-run = "my-app"to[package], naming your app's binary: the package name as written, hyphens included. -
Give
src/seeders/mod.rsa registry:use *; -
Create
src/bin/my-app-seed.rs, named after your package so that two projects installed withcargo installdo not collide.--listprints the seeders' names, which the CLI checks--seederagainst before it changes anything:async
Utility Commands
# Initialize a new project
# Show configuration
# List all models
# Show schema information
Global Options
All commands support these global options:
)
The generator commands (tideorm make ..., tideorm migrate generate, tideorm models)
run without a tideorm.toml and fall back to the built-in defaults. A tideorm.toml that
exists but cannot be read or parsed is always reported as an error instead - otherwise a
typo in the config would silently generate Postgres code into src/ for a project
configured for another backend.
Generated File Examples
Generated Model
//! User Model
//!
//! Auto-generated by TideORM CLI
use *;
use Post;
use Company;
Generated Migration
//! Migration: create_users_table
use *;
;
Generated Seeder
//! UserSeeder
use *;
use crateUser;
;
Environment Variables
The CLI supports environment variable expansion in tideorm.toml:
[]
= "${DATABASE_PASSWORD}"
Create a .env file:
DATABASE_PASSWORD=secret
License
MIT License - See LICENSE file for details.