The pg_semantius CLI
pg_semantius is a single self-contained program that talks to a PostgreSQL database and deploys the Semantius schema into it. It is how you install your own modules, and it is the only way to get the core onto a hosted database that does not allow extensions.
This is not the same program as the Semantius CLI. The names are close and the jobs are not. semantius is the tool your agents and scripts use to work with a running platform over HTTP. pg_semantius connects straight to a database with SQL and changes its schema. They are separate downloads, and both can sit on your machine at once.
Install It
On macOS, Linux, and Git Bash:
curl -fsSL https://raw.githubusercontent.com/semantius/semantius/main/install.sh | bashIn PowerShell on Windows:
irm https://raw.githubusercontent.com/semantius/semantius/main/install.ps1 | iexThe installer picks the right build for your machine, checks it against the published checksums, and puts it somewhere on your PATH. Open a fresh terminal afterwards, then check it:
pg_semantius --versionBuilds are published for Linux, Windows, and Apple Silicon Macs, on both Intel-style and ARM processors. There is no build for older Intel Macs. If you prefer to download one by hand, they are attached to every release with -cli- in the name, which is what separates them from the extension files on the same page.
The program needs nothing else installed. No runtime, no package manager, no checkout of the source. It carries the core SQL of the release it came from, so it works in an empty folder.
Point It at a Database
Every command needs a database to talk to. There are three ways to say which, and they are checked in this order:
- The
--database-urloption, which beats everything else. - A
DATABASE_URLenvironment variable. - A file named
.env.localin the folder you run it from.
The option is the clearest for one-off work:
pg_semantius connect --database-url postgresql://postgres:password@localhost:5432/semantiusconnect does nothing but check that the database answers, so it is a safe first command. If you work with more than one database, put each in its own .env.<name> file and select it with --env <name>.
The Commands Worth Knowing
| Command | What it does |
|---|---|
connect | Checks the connection and reports the server it reached |
migrate | Applies SQL migrations. Takes --apps <names> to say which |
test | Runs the test suite against the database |
docgen | Writes a schema.md describing every entity in the model |
pg_semantius --help lists the rest, including the tooling that generates type definitions for Drizzle and Kysely.
migrate is the one you will use. _core is the Semantius core itself. It is part of every run, added automatically whenever you name anything else, so this installs or updates the core on its own:
pg_semantius migrate --apps _coreTo deploy your own module, name its folder instead. To see the SQL without running it, add --script, which writes a file rather than touching the database.
If the folder you run it from has an apps/_core of its own, that copy is used instead of the one inside the program. When some of its files are not the ones this release carries, migrate lists them and asks you to type Y before it applies them, because a database that recorded such a copy of a run-once migration cannot be updated by a release later. Without a terminal to ask, it stops; --confirm skips the question.
test needs the pgTAP testing framework inside the target database. Install it with pg_semantius migrate --apps test, which is a normal thing to do on a development database and not something to run on a production one.
Keep It as New as the Database
Before it changes anything, migrate checks that the database is one it can update, and stops with an error otherwise:
- A newer
pg_semantiushas already migrated the database. The message ends withuse a newer pg_semantius. This happens even when you only deploy a module of your own, because_coreis part of every run. Run the installer again to get the current release, then repeat the command. - The database cannot be brought to this release. The message ends with
this database cannot be updated; replace the database with a fresh install. Install the core into a new database and move your data across.
Either way nothing has been changed.
Three Commands That Delete Everything
These exist because rebuilding a development database from scratch is a normal thing to do. They are also exactly what they sound like.
| Command | What it destroys |
|---|---|
dropall | Every object in the public schema. Tables, views, functions, the lot. |
reset | The same, then reinstalls a bare _core with no sample data |
retest | The same, then reinstalls _core, the sample module, and the tests, then runs them |
None of them can be undone. Without --confirm, each asks once before it starts: dropall wants you to type Y, reset and retest want yes. With --confirm there is no question at all, so check --database-url before you press enter, particularly if you keep several databases in .env files.
On Neon, Supabase, and Other Hosted Databases
Hosted providers do not let you install custom extensions, so the extension route is closed there. The CLI is the way in, and it produces an identical schema:
pg_semantius migrate --apps _core --database-url postgresql://...Use the project owner connection for this, because creating roles and event triggers needs those rights. Then switch your application to the semantius_authenticator account, and give that account a password of its own. An application left on the owner connection bypasses row-level security entirely and returns every row to every caller, with no error to warn you.
Next Steps
- Upgrade, Back Up, Remove: keeping an installed database current, and backing it up.
- Reference: the roles, the functions, and what the install creates.