Prerequisites & first project
Prerequisites
- Rust 1.94+ — install rustup
- A database: SQLite (nothing to install, the default), PostgreSQL 12+, or MySQL
rustc --version # 1.94 or later
1. Install the Runique CLI
cargo install runique --features sqlite --locked
The CLI connects to the database (create-superuser): it must be compiled with your engine's driver. Replace sqlite with postgres, mysql, or use all-databases for a binary that talks to all three. Without an engine feature, every connection fails with "driver not enabled".
--locked uses the dependency versions published with the crate; without it, Cargo may pick newer versions that don't work together.
To switch engines later, reinstall with --force:
cargo install runique --features postgres --locked --force
2. Create the project
runique new my_project
cd my_project
The name may only hold letters, digits, _ and -, can't start with a digit or -, and can't be a reserved name (a Rust keyword, std, core, test, a Windows device name such as con, or migration / runique, already taken in the generated project).
runique new writes a complete project, ready to run:
my_project/
├── Cargo.toml workspace: the app + its `migration` crate
├── .env settings, with a random SECRET_KEY of its own
├── migration/ the migration crate (Cargo.toml, src/main.rs, src/lib.rs)
├── src/
│ ├── main.rs the application builder
│ ├── url.rs the routes (/, /signup, /login, /logout, /about)
│ ├── views.rs the views
│ ├── forms/ sign up and sign in forms
│ └── entities/ your models (model!)
├── templates/ base.html (the layout), index, about, signup, login
├── static/css/
└── media/ favicon, logo, and the files users upload
The project uses SQLite by default. For another engine, see Database.
3. Create the framework's tables
runique migration up
The migration/ crate already holds the migrations of the framework's tables (eihwaz_users, sessions, rights, history, reset tokens). This command applies them. The first run compiles the crate, so it takes a while; later runs are quick.
Skip this step and the app still starts, but the first request touching a session fails with
no such table: eihwaz_sessions.
4. Run the server
cargo run
Expected output:
Runique is operational
└──> Server launched on http://127.0.0.1:3000
└──> Connected to database Sqlite -> data.db
└──> ctrl + c to stop
The home page comes with sign up, sign in and sign out.
5. Create a superuser (optional)
The `.env` file
runique new writes it for you:
IP_SERVER=127.0.0.1
PORT=3000
# `dev` or `prod`: sets how the application behaves (session cookie, startup checks,
# public URL, allowed hosts, template reload, logs). Unset or unknown: `prod`.
RUNIQUE_ENV=dev
# Shows the detailed error pages and turns every log channel on. It also works with
# RUNIQUE_ENV=prod to look into a problem on a live site, but every visitor then sees those
# pages, and the logs hold what visitors type in forms (passwords excepted): not recommended,
# turn it off as soon as you're done.
DEBUG=true
# Signs the CSRF tokens and the sessions: this project's own, keep it secret
SECRET_KEY=<64 hex characters generated by runique new>
DB_ENGINE=sqlite
DB_NAME=data.db
DATABASE_URL="sqlite://data.db?mode=rwc"
The SECRET_KEY is generated at random when the project is created. If you need to replace it (leak, new deployment), any random string of 32 characters or more will do, for instance:
openssl rand -hex 32
In production (RUNIQUE_ENV=prod), Runique refuses to start with a key that is missing, too short, or left at its example value.
The other variables (templates, static and media folders, logging…) have defaults: see Environment variables.
Using Runique from the repository (development version)
The repository holds the work in progress, ahead of the version published on crates.io. It carries a pre-release number (4.1.0-preview): what you clone is the last published version plus the changes of the most recent section of the CHANGELOG.
A pre-release does not exist on crates.io. A project created by a runique new installed from the repository therefore asks for runique = { version = "4.1.0-preview", … }, which Cargo will not find: replace that line with form 2 or 3 below.
runique is declared in two files of the project: the application's Cargo.toml and migration/Cargo.toml. Both must point at the same source. Three ways to choose it:
# 1. The published version (default)
runique = { version = "4.0.0", features = ["sqlite"] }
# 2. A local clone of the repository
runique = { path = "../runique/runique", features = ["sqlite"] }
# 3. Straight from GitHub
runique = { git = "https://github.com/seb-alliot/runique", branch = "main", features = ["sqlite"] }
With a local clone, the project's workspace saves writing the path twice: declare the source once at the root, then take it up in both crates.
# Cargo.toml (project root)
[workspace]
members = ["migration"]
[workspace.dependencies]
runique = { path = "../runique/runique" }
[dependencies]
runique = { workspace = true, features = ["sqlite"] }
# migration/Cargo.toml
[dependencies]
runique = { workspace = true, features = ["sqlite"] }
In every case, sea-orm and sea-orm-migration must keep the exact version this source of Runique is built with: take them from the Cargo.toml at the root of the repository.
Recommended tools (development)
rustup component add rust-analyzer clippy rustfmt
sea-orm-cli is not needed: runique migration up | down | status runs cargo run on the project's migration crate, whose main calls the CLI of the sea-orm-migration library. See The expected Cargo.toml.