Data: models, migrations, seeders and events
Carrier stores everything in one SQLite database through Tempest's ORM. Models are plain classes, tables are created by migration classes, and Tempest discovers both. This page covers how to add your own and lists what ships.
Where the database lives
app/Config/database.config.php returns an SQLiteConfig.
The path comes from DB_DATABASE; the default is storage/carrier.sqlite, and relative paths are
resolved from the project root.
DB_DATABASE=storage/carrier.sqliteAll nodes run in one PHP process and use this one file; see architecture.
Models
A model is a class using Tempest\Database\IsDatabaseModel. Public typed properties are columns,
in camelCase. Foreign keys are explicit int properties (userId, areaId), not relations.
namespace App\Models;
use DateTimeImmutable;
use Tempest\Database\IsDatabaseModel;
final class Oneliner
{
use IsDatabaseModel;
public ?int $userId = null;
public string $handle;
public string $text;
public DateTimeImmutable $createdAt;
}| Property type | Column |
|---|---|
string, int, bool |
string, integer, boolean |
?type |
nullable |
DateTimeImmutable |
datetime |
array |
JSON (User::$groups, User::$settings, DoorScore::$meta, DoorState::$state) |
The table name comes from the class (Oneliner → oneliners, MessagePointer →
message_pointers). Override it with #[Table('mail')], as App\Models\Mail does.
The primary key is $model->id, a PrimaryKey object: read the number with $model->id->value.
User, MessageArea and others add a key(): int helper for that.
Queries
The forms used in this codebase:
// many rows
$top = DoorScore::select()
->where('door = ?', 'viper')
->orderBy('score', Direction::DESC)
->limit(10)
->all();
// one row, or null
$area = MessageArea::select()->where('key = ?', 'lobby')->first();
$user = User::select()->whereRaw('lower(handle) = ?', mb_strtolower($handle))->first();
$any = Oneliner::select()->orderByRaw('random()')->first();
// count
$unread = Mail::count()->where('toUserId = ? AND readAt IS NULL', $userId)->execute();
// aggregate
$newest = Message::select()->where('areaId = ?', $areaId)->max('id');
// by id
$caller = Caller::get($id);
// insert
Oneliner::create(handle: 'Ghost', text: 'first!', createdAt: new DateTimeImmutable());
// update, delete
$user->securityLevel = 30;
$user->save();
$user->delete();Direction is Tempest\Database\Direction. where() takes a SQL fragment with ? placeholders
and the values after it.
Migrations
A migration is a class implementing Tempest\Database\MigratesUp with a $name and an up()
returning a statement. Tempest discovers migration classes in app/ and in the framework, and
runs each name once.
-
Add
app/Migrations/CreateRumorsTable.php:namespace App\Migrations; use Tempest\Database\MigratesUp; use Tempest\Database\QueryStatement; use Tempest\Database\QueryStatements\CreateTableStatement; final class CreateRumorsTable implements MigratesUp { public string $name = '2026-12-01_000001_create_rumors_table'; public function up(): QueryStatement { return new CreateTableStatement('rumors') ->primary() ->integer('userId', nullable: true) ->string('text', 120) ->datetime('createdAt') ->index('createdAt'); } } -
Run it:
php carrier migrateEach migration prints
Migrated <name>.
Names follow YYYY-MM-DD_NNNNNN_description. The shipped ones are
2026-11-28_000001_create_users_table (framework) through
2026-11-28_000013_create_door_states_table (board).
Column builders used in the repository: primary(), integer(), string($name, $length),
text(), boolean(), datetime(), json(), each taking nullable: and default:; and
index(...$columns), unique(...$columns).
| Command | Effect |
|---|---|
php carrier migrate |
run migrations not yet run |
php carrier migrate --fresh |
drop every table first |
php carrier migrate --seed |
run the seeders afterwards |
php carrier db:seed |
run the seeders only |
Source: MigrateCommand.php. See also console.
Seeders
A seeder implements Tempest\Database\DatabaseSeeder; Tempest discovers it and db:seed runs
it. Constructor parameters are injected.
final readonly class BoardSeeder implements DatabaseSeeder
{
public function __construct(private BbsConfig $config)
{
}
public function run(string|UnitEnum|null $database): void
{
if (Oneliner::count()->execute() === 0) {
Oneliner::create(handle: 'Ghost', text: 'first! ...or so it says', createdAt: new DateTimeImmutable());
}
}
}The board's BoardSeeder.php creates three conferences with
eight message areas (one, sysop, readable only with SY), a welcome thread in the lobby, a
poll and three oneliners. Each part is skipped when its table already has rows, so running it
twice is safe. It creates no users.
Events
The framework dispatches these through Tempest's event bus:
| Event | Dispatched | Source |
|---|---|---|
Carrier\Events\SessionStarted |
a caller connected, before the connection pipeline | NodeManager.php |
Carrier\Events\UserLoggedIn |
Session::login() |
Session.php |
Carrier\Events\UserLoggedOut |
the call ends while logged in, after time online is saved | NodeManager.php |
Carrier\Events\SessionEnded |
the call ends, logged in or not | NodeManager.php |
Carrier\Door\DoorEntered |
a door starts | DoorManager.php |
Carrier\Door\DoorExited |
a door ends, also after a crash | DoorManager.php |
Each carries public Session $session; the door events add public string $door.
Handle one by marking a method #[EventHandler] with the event as its parameter type. The board's
call log (CallLog.php) records Last Callers and tells the other
nodes:
use Carrier\Events\UserLoggedIn;
use Carrier\Session\NodeMessage;
use Tempest\EventBus\EventHandler;
final class CallLog
{
#[EventHandler]
public function loggedIn(UserLoggedIn $event): void
{
$session = $event->session;
// record a Caller row, then:
$session->nodes->broadcast(new NodeMessage("{$session->handle()} just logged in."), $session);
}
}Dispatch your own event object with Tempest\EventBus\event($event); any class works as an event.
Reference: the shipped models
Carrier\Auth\User (table users)
Owned by the framework: User.php, CreateUsersTable.php.
| Column | Type | Default | Notes |
|---|---|---|---|
handle |
string(24) | — | unique; lookups ignore case |
password |
string | '' |
always a hash; Argon2id when PHP has it, else PASSWORD_DEFAULT |
realName, location |
?string(48) | null | |
email |
?string(96) | null | |
securityLevel |
int | 20 | see configuration for levels |
flags |
string(26) | '' |
single letters, e.g. AB; checked with ACS FL[A] |
groups |
JSON list | [] |
e.g. ['users', 'sysops']; ACS GM[sysops] |
calls, posts |
int | 0 | |
minutesToday |
int | 0 | counts for minutesDate |
minutesDate |
?string(10) | null | Y-m-d |
settings |
JSON object | {} |
per-caller preferences, below |
lastLoginAt, createdAt |
?datetime | null |
| Method | Does |
|---|---|
User::findByHandle($handle) |
case-insensitive lookup, trimmed |
User::register($handle, $password, $level, $groups = ['users'], ...$fields) |
hash, set createdAt, save; extra named fields are set as properties |
setPassword($password), checkPassword($password), needsRehash() |
password hash handling |
hasFlag($flag), inGroup($group) |
case-insensitive checks |
setting($key, $default), putSetting($key, $value) |
read and write settings; call save() after |
minutesUsedToday() |
minutesToday if minutesDate is today, else 0 |
key() |
the id as an int |
Setting keys used by the code:
| Key | Values | Set by |
|---|---|---|
theme |
theme name | Settings |
menu_style |
lightbar, hotkey |
Settings |
encoding |
auto, utf8, cp437 |
Settings |
colors |
auto, aixterm, 256, rgb |
Settings; see art |
baud |
0 (off), 300 … 57600 | Settings |
available |
bool | Settings (pages and chat) |
locked |
bool | sysop user editor; a locked user cannot log in |
Board models (app/Models)
| Model | Table | Columns | Helpers |
|---|---|---|---|
Caller |
callers |
userId, node, protocol(16), address(64)?, terminal(64)?, actions(16) = '', loggedInAt, loggedOutAt? |
— |
Conference |
conferences |
key(24, unique), name(48), description?, acsRead?, sort = 0 |
— |
MessageArea |
message_areas |
conferenceId, key(24, unique), name(48), description?, acsRead?, acsWrite?, anonymous = false, sort = 0 |
key(), messageCount(), unreadFor($userId), newestId() |
Message |
messages |
areaId, replyToId?, userId?, fromName(48), toName(48) = All, subject(72), body, createdAt |
— |
MessagePointer |
message_pointers |
userId, areaId (unique pair), lastReadId = 0 |
lastRead($userId, $areaId), mark($userId, $areaId, $messageId) (only moves forward) |
Mail |
mail |
fromUserId?, toUserId, replyToId?, fromName(48), subject(72), body, readAt?, deletedBySender = false, deletedByRecipient = false, createdAt |
unreadFor($userId), inbox($userId) (newest first) |
Oneliner |
oneliners |
userId?, handle(24), text(80), createdAt |
— |
Poll |
polls |
userId?, question(120), allowNewOptions = true, closesAt?, createdAt |
isOpen() |
PollOption |
poll_options |
pollId, text(72) |
— |
PollVote |
poll_votes |
pollId, pollOptionId, userId, createdAt; one vote per user per poll |
— |
DoorScore |
door_scores |
door(32), userId?, handle(24), score, meta JSON = [], createdAt |
top($door, $limit = 10) |
DoorState |
door_states |
door(32), userId (unique pair), state JSON = {}, updatedAt |
fetch($door, $userId), put($door, $userId, $state) |
? marks a nullable column; (n) a string length. Caller::$actions holds one letter per thing
done on the call: P posted, M mailed, D door, O oneliner, V voted, C chat
(Activity.php).