v0.1.0

Create a first project

Start a project from scratch, change it with a changeset, lint it and generate SQL, without a database.

A databee project is a folder. Create one:

databee init --name shop

It writes project.toml, an empty schema/ and a .gitignore that excludes .databee/ and out/. The default dialect is PostgreSQL; --dialect mysql|sqlite|mongodb|mssql starts a project of another dialect.

Change the model with a changeset

The model changes through changesets: a JSON document with the revision it was written against and a list of operations. Print the revision, then write the changeset (this one creates a namespace, two tables and a foreign key):

databee revision
{
  "base_revision": "<the revision printed above>",
  "ops": [
    { "op": "add_namespace", "name": "shop" },
    { "op": "add_entity", "ref": "customer", "namespace": "shop", "name": "customer",
      "fields": [
        { "name": "id", "type": { "kind": "int", "bits": 64 } },
        { "name": "email", "type": { "kind": "text" }, "sensitive": true }
      ],
      "primary_key": ["id"] },
    { "op": "add_entity", "ref": "order", "namespace": "shop", "name": "order",
      "fields": [
        { "name": "id", "type": { "kind": "int", "bits": 64 } },
        { "name": "customer_id", "type": { "kind": "int", "bits": 64 } },
        { "name": "total", "type": { "kind": "decimal", "precision": 12, "scale": 2 } }
      ],
      "primary_key": ["id"] },
    { "op": "add_foreign_key", "entity": "@order", "fields": ["customer_id"],
      "target_entity": "@customer" }
  ]
}

ref gives a new object a label, and later operations in the same changeset refer to it as @label. Apply it, first as a dry run:

databee changeset apply shop.changeset.json --dry-run
databee changeset apply shop.changeset.json

The changeset is checked as a whole and written all or nothing. databee changeset schema prints the JSON Schema of changesets for editors and agents. More in changesets and undo.

Check and generate

databee inspect
databee lint

lint starts with a verdict line ([WARN] Project `shop`: 0 errors, 1 warning, 0 info in plain output), groups the findings by severity and ends with next steps. It reports PG002 here: the foreign key on order has no index that starts with customer_id, and a fix is available. databee lint --fix adds the index. Then write the SQL:

databee generate ddl
CREATE SCHEMA IF NOT EXISTS "shop";

CREATE TABLE "shop"."customer" (
    "id" bigint NOT NULL,
    "email" text NOT NULL,
    CONSTRAINT "customer_pkey" PRIMARY KEY ("id")
);

followed by the order table, its foreign key and the index. Nothing connected to a database. If you do not like the last change, databee undo takes it back.

Next

Validate and lint explains the checks, Render a diagram draws the model.

Edit this page on GitHub · Docs for v0.1.0