# Oxid

Source: https://docs.ops0.com/docs/iac/oxid

Oxid is a Rust-based Infrastructure as Code engine supported natively in ops0. It uses the same HCL syntax as Terraform and OpenTofu but is backed by a PostgreSQL database rather than cloud-provider APIs — making it ideal for managing application-layer configuration, internal tooling infrastructure, and database schema state.

**Beta**

Oxid support in ops0 is currently in beta. A disclaimer is shown on first use. Core functionality (plan, apply, destroy, SQL console) is stable.

---

## Creating an Oxid Project

### Navigate to IaC
Click **IaC** in the sidebar.

### Click New Project
Select **+ New Project**.

### Select Oxid as the engine
In the **IaC Type** dropdown, choose **Oxid**.

### Acknowledge the beta disclaimer
A one-time disclaimer is shown explaining Oxid's beta status. Click **Continue**.

### Configure and create
Name the project and click **Create**.

---

## Enabling the Oxid Backend

Oxid requires a PostgreSQL database connection to store state and manage resources. After creating an Oxid project, you need to enable the backend.

### Open project settings
In the IaC editor, click **Settings** in the project toolbar, then select **Oxid Backend**.

### Click Enable Oxid
Click the **Enable Oxid** button.

### Enter a database URL
Provide a PostgreSQL connection string:

```
postgresql://user:password@host:5432/dbname?sslmode=require
```

### Save
Click **Save**. ops0 tests the connection and stores the URL encrypted.

### Connection String Format

| Component | Example | Notes |
|-----------|---------|-------|
| User | `myuser` | Database user |
| Password | `secret` | URL-encoded if it contains special characters |
| Host | `db.example.com` | Hostname or IP |
| Port | `5432` | Default PostgreSQL port |
| Database | `mydb` | Database name |
| SSL mode | `sslmode=require` | Recommended for production |

### Editing and Disabling

| Action | How |
|--------|-----|
| **Edit** | Click **Edit Oxid** in project settings to update the database URL |
| **Disable** | Click **Disable Oxid** — removes the backend config (does not delete the database) |

---

## Deploying with Oxid

Oxid deployments follow the same plan → apply workflow as Terraform:

1. Click **Deploy** in the editor toolbar
2. Review the plan output
3. Click **Apply** to execute

Oxid runs `oxid init`, `oxid plan`, and `oxid apply` internally. Output is streamed to the deployment log in real time.

### Oxid Plan Output

```
Oxid will perform the following actions:

  + oxid_database_user.app_user
      username: "app_user"
      database: "mydb"

  + oxid_schema.public_ext
      name: "extensions"

Plan: 2 to add, 0 to change, 0 to destroy.
```

---

## SQL Console

Oxid projects with a configured backend include a built-in SQL console for querying the connected PostgreSQL database directly from ops0.

### Accessing the Console

1. Open an Oxid IaC project with a configured backend
2. Click **SQL Console** in the project toolbar (or **Invent** if labeled)

### Console Features

| Feature | Description |
|---------|-------------|
| **Schema browser** | View all tables and columns in the connected database |
| **Query editor** | Write and execute SQL queries |
| **Result table** | Paginated results (up to 1,000 rows) |
| **Saved queries** | Save frequently used queries with a name |
| **Query timeout** | Queries time out after 30 seconds |

### Schema Browser

The schema browser shows all tables in `information_schema` for the connected database:

```
Tables in mydb:
├── users          (id, email, created_at, updated_at)
├── teams          (id, name, org_id, created_at)
├── memberships    (user_id, team_id, role)
└── audit_events   (id, user_id, action, resource, timestamp)
```

Click any table to auto-fill a `SELECT * FROM <table> LIMIT 100` query.

### Running Queries

```sql
-- Example: find all users created in the last 7 days
SELECT id, email, created_at
FROM users
WHERE created_at > NOW() - INTERVAL '7 days'
ORDER BY created_at DESC;
```

Click **Run** or press `Ctrl+Enter` / `Cmd+Enter`.

### Saving Queries

1. Write a query in the editor
2. Click **Save Query**
3. Enter a name
4. Click **Save**

Saved queries appear in the **Saved** panel on the left. Click any saved query to load it into the editor.

**Write operations**

The SQL console runs queries directly against your database with the credentials provided in the Oxid backend configuration. There is no read-only mode — destructive queries (DELETE, DROP, TRUNCATE) will execute. Use with care.

---

## Oxid vs Terraform

| Feature | Terraform / OpenTofu | Oxid |
|---------|---------------------|------|
| **Target** | Cloud provider APIs | PostgreSQL database |
| **State backend** | S3, GCS, Azure Blob, local | PostgreSQL (built-in) |
| **Syntax** | HCL | HCL (compatible) |
| **SQL Console** | No | Yes |
| **Use case** | Cloud infrastructure | DB-backed resources, app config |

---

## Related

- [Projects](https://docs.ops0.com/docs/iac/projects): Create and manage IaC projects

- [Advanced](https://docs.ops0.com/docs/iac/advanced): Backend configuration and state management

- [Deployments](https://docs.ops0.com/docs/iac/deployments): Plan, apply, and track deployments
