Installation & Setup

Runique CLI

The CLI creates projects, writes and applies migrations, creates the first superuser and runs the business tests. Run it from the project root (where .env is).

Every command

runique new <name>                # Create a new project
runique makemigrations            # Write the migrations of the models that changed
runique makemigrations --force    # Same, allowing destructive changes
runique migration up              # Apply every pending migration
runique migration down -n 1       # Roll back the last migration (its down() runs)
runique migration status          # List the migrations and their state
runique create-superuser          # Create a superuser
runique test [file] [test]        # Run src/runique_test/ (see Tests)
runique --version                 # Version of the installed command (also: -V)

runique --version shows the name and the version of the command, for example runique-cli 0.1.0. The command lives in its own crate, runique-cli, and has its own version: it is not that of your project's runique crate, and the two evolve separately.

No runique start: the app runs with cargo run. The admin is declared in Rust (ModelAdmin + .with_admin(...)), with no daemon and no code generation.


`runique new`

Creates the whole project: the app, the migration/ crate, templates, CSS, and a .env with a random SECRET_KEY. See Prerequisites & first project.

The project is written as one batch: whole, or not at all. After a power cut halfway through, run the same command again with the same name: it removes the unfinished project, then creates it. See Atomic file writes.

Refused names: empty, characters other than letters / digits / _ / -, starting with a digit or -, Rust keywords, built-in crates (std, core, alloc, proc_macro, test), cargo's folders (build, deps, examples, incremental), Windows device names (con, nul, com1…), and migration / runique. The comparison ignores case and reads - as _.


`runique makemigrations`

runique makemigrations [--entities src/entities] [--migrations migration/src] [--force]

Reads the model!{} and extend!{} blocks of src/entities/, compares them to their snapshots, and writes the migrations. When the migration/ crate doesn't exist yet (a project not created by runique new), it is created, with the engine of DB_ENGINE (SQLite when unset). Details: Migrations.

The command connects to the database of the .env first (DATABASE_URL, otherwise the DB_* keys): when it doesn't answer, it stops with an error and writes nothing. It never changes the database; runique migration up is what applies.

It then reads the migrations already applied (the seaql_migrations table) and refuses to go on when one of them is not in migration/src/lib.rs: the database belongs to another project, or the file of an applied migration was deleted. The framework's migrations (accounts, sessions, history) are always known. The message lists the migrations involved, and nothing is written.

Before anything is computed, every .rs file of migration/src/snapshots/ and snapshots/runique/ is read again: a snapshot that can't be read, or whose file name is not the name of the table it describes, stops the command. The other files of the folder are ignored.

The files are written as one batch. A run a power cut interrupted is repaired by the next one, before anything is computed.


`runique migration up | down | status`

runique migration up [--entities src/entities] [--migrations migration/src]
runique migration down [-n 1] [--migrations migration/src]
runique migration status [--migrations migration/src]

Runs the project's migration crate (cargo run on migration/Cargo.toml), which reads DATABASE_URL from .env. sea-orm-cli isn't needed: the SeaORM version that applies the migrations is the one migration/Cargo.toml pins, the same as runique's.

Once up succeeded, Runique records what was just applied, as one batch of files: every pending migration loses its // runique: waiting migrate up line, and the snapshot of each table it changes is written from its model (--entities). A model with no applied migration gets no snapshot. With no pending migration (a server applying migrations already run elsewhere), the models folder isn't read and nothing is written.

Don't change a model between runique makemigrations and runique migration up: the snapshot is written from the model as it is when the migration is applied, and would be ahead of the database.

These three commands refuse to start as long as an interrupted makemigrations hasn't been repaired: run runique makemigrations again first.


`runique create-superuser`

Creates an active superuser account, activated at once. The command reaches the database as the app does: DATABASE_URL, or DB_ENGINE + DB_*, from .env. Apply the migrations first.

The wizard goes through five steps, with keyboard menus (arrows + Enter):

  1. Hashing algorithm: Argon2 (recommended), Bcrypt, Scrypt, or a custom provider
  2. Username: refused when empty or already taken
  3. Email: refused when invalid or already taken
  4. Password, then its confirmation
  5. Review: confirm and create, change the algorithm, or change the password

The password needs at least 12 characters, with a lowercase letter, an uppercase letter, a digit and a special character. Ctrl+C cancels at any time.

The CLI runs without the app: it can't see the PasswordConfig of main.rs, so the algorithm is picked on each run. Pick the app's; otherwise the hash is moved to the configured algorithm on the first successful sign-in (Auto mode).

Custom provider: give the path of an executable (not a symbolic link) that reads the password on stdin and writes the hash on stdout. It runs without a shell and must answer within 10 seconds.


`runique test`

Runs the tests of src/runique_test/, each inside a transaction rolled back at the end. The command refuses to run when the test-utils feature is missing, or declared under [dependencies] instead of [dev-dependencies] (it would then ship in the production binary). See Tests.