diff --git a/.agents/skills/extenddb/references/samples/01-venv-setup.md b/.agents/skills/extenddb/references/samples/01-venv-setup.md index 58e429b4b..e9191867f 100644 --- a/.agents/skills/extenddb/references/samples/01-venv-setup.md +++ b/.agents/skills/extenddb/references/samples/01-venv-setup.md @@ -14,7 +14,7 @@ test -d ~/venvs/extenddb-venv && echo "found extenddb-venv in ~/venvs/" || true Two standard locations: - `.venv/` at the repo root, created by `scripts/install-linux.sh` and `scripts/install-macos.sh` (recommended). -- `~/venvs/extenddb-venv/`, created by the README instructions. +- `~/venvs/extenddb-venv/`, created by the Python Environment Setup instructions in `docs/manuals/06-developer-test-guide.md`. Either works. If both exist, prefer `.venv/` since the install scripts maintain it. diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 04fd3a1e6..b7f9501c5 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -47,9 +47,9 @@ jobs: timeout-minutes: 30 env: # The wasm-pack release to install; the comment on the wasm tooling - # steps below says why. README.md's "Building it" describes what one - # named wasm-pack release does, so a change of this value needs that - # section checked against the new release, and the release it names + # steps below says why. docs/webassembly.md's "Building it" describes + # what one named wasm-pack release does, so a change of this value needs + # that section checked against the new release, and the release it names # changed to match. WASM_PACK_VERSION: "0.15.1" steps: @@ -87,11 +87,11 @@ jobs: # below, read the description the crate's macros put into the module, # and both stop with a "different bindgen format" error when that # description's schema version is not their own; the corpus step's - # wasm-pack needs a wasm-bindgen of that version too (README.md's - # "Building it" says where it looks for one). The cache key holds both - # versions, so a cache hit restores tools of those versions and a miss - # installs them; both land in ~/.cargo/bin, and a hit skips their - # multi-minute compile. + # wasm-pack needs a wasm-bindgen of that version too + # (docs/webassembly.md's "Building it" says where it looks for one). The + # cache key holds both versions, so a cache hit restores tools of those + # versions and a miss installs them; both land in ~/.cargo/bin, and a hit + # skips their multi-minute compile. - name: Read the wasm-bindgen version from Cargo.lock id: wasm-bindgen run: | diff --git a/AGENTS.md b/AGENTS.md index cc882d31e..f457ed588 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -428,6 +428,7 @@ Expression parsing lives in `crates/core/src/expression/`. This is pure sync Rus | Cassandra Setup | `docs/cassandra-setup.md` | Cassandra install, config, and deployment (experimental) | | Testing Design | `docs/design/09-testing.md` | Test strategy and infrastructure | | Extending Storage | `docs/manuals/12-extending-extenddb-storage.md` | Guide to implementing storage backends | +| Experimental: WebAssembly Build | `docs/webassembly.md` | What the browser build does, refuses and skips; how to build it | Build PDFs: diff --git a/README.md b/README.md index f8b606a5b..daf42925b 100755 --- a/README.md +++ b/README.md @@ -5,166 +5,196 @@ > a clean-room implementation that speaks the DynamoDB wire protocol. Behavioral differences from the real service are > documented in [Differences from DynamoDB](docs/differences-from-dynamodb.md). -A DynamoDB-compatible API adapter, ExtendDB speaks the DynamoDB wire protocol — any AWS SDK, CLI, or tool that works -with DynamoDB works with ExtendDB, unchanged. - -## Use Cases - -- **Local development** — run DynamoDB workloads on your laptop with zero cloud dependency -- **CI/CD pipelines** — deterministic integration tests against a DynamoDB-compatible backend -- **Self-hosted deployments** — run DynamoDB workloads on your own infrastructure (on-premises, private cloud, edge) -- **Multi-cloud** — use DynamoDB semantics on any cloud that runs an ExtendDB-supported database backend -- **Air-gapped environments** — DynamoDB functionality with no internet connectivity - -## Scope - -ExtendDB is a server that implements the Amazon DynamoDB API on a database that you provide: PostgreSQL, SQLite, MongoDB or Cassandra. An application connects to it through the endpoint setting of an AWS SDK or the AWS CLI. The application signs each request with an access key stored in ExtendDB. +ExtendDB is a server that speaks the Amazon DynamoDB API and stores your tables in PostgreSQL, SQLite, MongoDB or Cassandra. Point an AWS SDK or the AWS CLI at its endpoint, sign requests with an access key stored in ExtendDB, and your DynamoDB code runs against a database you operate: on a laptop, in CI, on premises or on a network with no internet access. + +[Install](#install) · [First request](#make-your-first-request) · [Storage backends](#storage-backends) · [Differences from DynamoDB](docs/differences-from-dynamodb.md) + +The AWS CLI reading back an item it wrote to a local ExtendDB server (the commands are in [Make your first request](#make-your-first-request)): + +```text +$ aws dynamodb get-item --endpoint-url https://127.0.0.1:18443 \ + --table-name Music \ + --key '{"Artist": {"S": "No One You Know"}, + "SongTitle": {"S": "Call Me Today"}}' +{ + "Item": { + "Artist": { + "S": "No One You Know" + }, + "SongTitle": { + "S": "Call Me Today" + }, + "Year": { + "N": "2025" + } + } +} +``` -ExtendDB 1.0 is for: +## Features -- Local development and continuous integration (CI) test runs. -- Self-hosted deployments: on premises, in a private or public cloud, at the edge, or on a network with no internet access. +- **DynamoDB clients work with an endpoint change.** Tables, items, Query and Scan, secondary indexes, batches, transactions and streams use the DynamoDB wire protocol. An application sets the ExtendDB endpoint and region, trusts its certificate and signs with an ExtendDB key, and needs no other code change for the [operations ExtendDB serves](#supported-operations). +- **Your choice of database.** Build for PostgreSQL, SQLite, MongoDB or Cassandra. Each binary serves one backend, and each backend has a [support tier](#storage-backends). The SQLite build needs no database server. +- **IAM built in.** Every DynamoDB API request must be SigV4-signed, and the server checks it against IAM policies (the dev-mode build for local development skips that check). Manage users, groups, roles, policies and permissions boundaries with `extenddb manage`, and all but permissions boundaries in the web console at `https://127.0.0.1:18443/console/`. +- **Backup and restore.** `CreateBackup` and `RestoreTableFromBackup` back up a table and restore it, to and from a filesystem or S3 backup store that you configure, or the catalog ([Your data](#your-data) says which). +- **Streams, TTL and PartiQL.** Read changes with `GetRecords`, expire items with Time to Live, and run PartiQL statements with `ExecuteStatement`. +- **Vector search.** Find the nearest items to a vector with `SearchVectors`, on PostgreSQL and SQLite. +- **Runs under a supervisor.** `serve --foreground` logs to stderr, `extenddb healthcheck` is a liveness probe that needs no shell, and `/metrics` returns metrics as JSON to a request with admin credentials. +- **Runs in a web page (experimental).** The [WebAssembly build](docs/webassembly.md) answers DynamoDB requests from JavaScript inside the browser, over an in-memory SQLite database, with no ExtendDB server, no IAM and no persistence. -ExtendDB 1.0 is not: +## Install -- Amazon DynamoDB: ExtendDB is a separate implementation of the API. [Differences from DynamoDB](docs/differences-from-dynamodb.md) lists the known differences and the operations that ExtendDB does not implement, for example global tables. -- A managed service: you provide the database, and the database's own tools handle replication, failover and database backups. -- A multi-server deployment: run one ExtendDB server for each catalog. In 1.0, more than one server on one catalog is not supported. +Building from source needs git, Rust 1.94.0 or later ([rustup](https://rustup.rs)) and a C toolchain (compiler, linker and C library headers). The first request below also needs the AWS CLI version 2. The SQLite backend runs inside the server process, so this route needs no database server: -[Storage backends](#storage-backends) says what 1.0 promises for each backend. The [versioning policy](docs/versioning.md) says what a release can change. +```sh +git clone https://github.com/ExtendDB/extenddb.git +cd extenddb +cargo build --release -p extenddb --no-default-features --features sqlite +``` -## Features +The binary is `target/release/extenddb`. Continue with [Make your first request](#make-your-first-request). -- Full DynamoDB wire protocol: CRUD, Query, Scan, Batch, Transactions, Streams, TTL, Import/Export -- Pluggable storage: PostgreSQL (default), SQLite, MongoDB, and Cassandra -- SigV4 authentication with IAM compatibility: users, groups, roles, policies, permissions boundaries -- Web management console for account and credential administration -- TLS with automatic self-signed certificate generation (replaceable with CA-signed certs) -- CSRF protection, security headers, session management -- JSON metrics endpoint with DynamoDB CloudWatch-style metric names and dimensions -- Daemon mode with syslog logging, plus `--foreground` for container and supervisor environments +Other routes: -## Storage backends +- **PostgreSQL** (the default build): `cargo build --release`, and a PostgreSQL 14 or later server. `init` connects to the server you name with `--pg-host` and `--pg-port`, as the admin role you name with `--pg-user`, and reads that role's password from `EXTENDDB_PG_PASSWORD` ([remote PostgreSQL](docs/getting-started.md#remote-postgresql--aurora), [local setup](docs/local-postgres-setup.md)). +- **MongoDB** or **Cassandra**: `cargo build --release --no-default-features --features mongodb` (or `cassandra`). Initialize with the [MongoDB](docs/local-mongodb-setup.md#initializing-extenddb-with-mongodb) or [Cassandra](docs/cassandra-setup.md) setup guide. On MongoDB, `init` needs an `extenddb.toml` that already holds the connection string, and the first request needs an account that you create; the MongoDB guide gives both steps. +- **Container images** that hold the server only and connect to a database you run: [PostgreSQL](docker/README.md), [MongoDB](docker/README-mongodb.md), [Cassandra](docker/README-cassandra.md). The SQLite backend has no production image. +- **For local development and CI**, the [`@extenddb/dev`](packaging/npm/README.md) npm package and the [`extenddb/extenddb-dev`](docs/dev-image.md) image run a dev-mode SQLite build. Dev mode uses plain HTTP and seeds an example key that can do everything, so keep a dev-mode server on loopback. At startup it migrates a catalog that is behind it, after it copies the database file. +- **Installer scripts** that check for Rust, PostgreSQL and Python 3, then install the Python requirements into `.venv` (from the network), build the PostgreSQL binary and build the PDF manuals: `scripts/install-linux.sh` and `scripts/install-macos.sh` ([Linux](docs/manuals/08-install-linux.md), [macOS](docs/manuals/09-install-macos.md)). +- **In a web browser**: the [experimental WebAssembly build](#experimental-webassembly-build) answers DynamoDB requests from JavaScript, with no ExtendDB server. You build it with `wasm-pack`, as [Building it](docs/webassembly.md#building-it) describes. -An ExtendDB binary contains one storage backend, which the build selects. The tier of a backend says what the 1.x releases promise for it: +To update, stop the server, run `git pull` and the same `cargo build`, run `./target/release/extenddb migrate` to list pending migrations and `./target/release/extenddb migrate --yes` to apply them, then start the server again. -- Stable: for production. The [versioning policy](docs/versioning.md) applies in full. The ExtendDB CI is reliably green for the backend. -- Beta: for production within the known limits in the table. The ExtendDB CI is reliably green for the backend. The versioning policy applies with one exception. To remove a known limit, a minor release can change the behavior that the table lists, and its release notes name the change. -- Experimental: for evaluation. The backend is not for production use. The versioning policy does not apply. A release can change the backend's behavior or configuration with no deprecation period. +## Make your first request -A backend moves up one tier in a minor release. Before that release, the maintainers agree in an issue that the ExtendDB CI has been reliably green for the backend. They also agree that its known limits fit the higher tier. The release notes name the move. A backend moves down a tier only through the [deprecation steps](docs/versioning.md#deprecation) of the versioning policy. +Run these from the `extenddb` folder after the SQLite build. On PostgreSQL, add the connection flags above to `init`. On Cassandra, run `init` as its setup guide gives it. The steps after `init` are the same on these three builds. On MongoDB, run `init` as its setup guide gives it, and in step 3 set `ACCOUNT_ID` with the guide's `create-account` line in place of the `list-accounts` one. The commands use bash or zsh (Linux, macOS, or WSL on Windows). -| Backend | Tier | Topology | Data across upgrades | API coverage | CI | Known limits | -|---|---|---|---|---|---|---| -| PostgreSQL | Stable | PostgreSQL 14 or later, on the same host, on another host or as a managed service. | `extenddb migrate --yes` migrates the catalog in place. CI upgrades catalogs that 0.1.14 and earlier releases created. | The operations in [Supported Operations](#supported-operations). Vector search needs the pgvector extension. | `integration`, required, on PostgreSQL 16 | Time to Live (TTL) removes about 100 expired items per table per minute. | -| SQLite | Stable (single node) | SQLite runs in the server process. A lock file allows one server for each database file. There is no production image, so build from source. | As PostgreSQL. `migrate --yes` copies the database file before its first change. | The operations in Supported Operations. | `integration`, required | One write transaction at a time. TTL as PostgreSQL. | -| MongoDB | Beta | MongoDB 7.0 or later, as a replica set, also for one node. | As PostgreSQL. | No vector search. On a global secondary index (GSI) with more than one RANGE attribute, `Query` takes a key condition on the first one only. | `mongodb-integration`, required, on MongoDB 7 | A number in a key attribute has at most 34 significant digits. The database names are fixed, so one replica set holds one catalog. TTL as PostgreSQL. | -| Cassandra | Experimental | Cassandra 4.1 or later, with `PasswordAuthenticator`. Each table takes its writes in one datacenter. | `migrate --yes` migrates the catalog. No rollback procedure is tested. | No vector search. CreateBackup keeps each backup in the catalog, with or without a backup store. The `Query` limit of MongoDB on a GSI with more than one RANGE attribute. | `cassandra-integration`, required, on Cassandra 4.1 | Some management operations are not atomic. A few known race conditions are open. TTL removes about 1,000 expired items per table per minute. See [Known Limitations](docs/cassandra-setup.md#known-limitations). | +**1. Initialize.** `init` creates the catalog (the database that holds table definitions, accounts, users, policies, access keys and settings; see [Catalog Model](docs/manuals/01-architecture-guide.md#catalog-model)), an `admin` user, a TLS certificate in `~/.extenddb/tls/` and `extenddb.toml`. On SQLite the catalog and the tables share one file, `extenddb.sqlite`. `init` prints the admin password once; save it. -On every backend, run one ExtendDB server for each catalog. Only SQLite enforces this. [Differences from DynamoDB](docs/differences-from-dynamodb.md) lists the differences of each backend from the service. +```sh +./target/release/extenddb init +``` -The `@extenddb/dev` npm package and the `extenddb/extenddb-dev` image run a dev-mode SQLite build, for local development and CI. Dev mode uses plain HTTP and seeds an example key that can do everything, so keep a dev-mode server on loopback. At startup it migrates a catalog that is behind it, after it copies the database file. +**2. Start the server.** It listens on `https://127.0.0.1:18443` and runs in the background. -## Quick Start +```sh +./target/release/extenddb serve +``` -```bash -# Build -cargo build --release +**3. Create an access key.** These commands create a user named `dev`, allow it every DynamoDB action, and print its key. First run this line on its own, type or paste the admin password (it is not echoed) and press Enter; `manage` reads it from `EXTENDDB_PASSWORD`: -# Initialize (creates databases, admin credentials, TLS cert, config file) -./target/release/extenddb init +```sh +read -rs EXTENDDB_PASSWORD && export EXTENDDB_PASSWORD +``` -# Start -./target/release/extenddb serve --config extenddb.toml - -# Use with any AWS SDK (TLS with self-signed cert — trust via AWS_CA_BUNDLE) -export AWS_CA_BUNDLE=~/.extenddb/tls/cert.pem - -# Requests must be signed with an access key this server issued. Create an IAM -# user, attach a policy that allows DynamoDB, and create an access key for the -# user, with the admin password that init printed. manage reads the password -# from EXTENDDB_PASSWORD, which keeps it out of the shell history and the -# process list. list-accounts prints the account_id of the default account -# that init created. -read -rs EXTENDDB_PASSWORD && export EXTENDDB_PASSWORD # the admin password, not echoed -./target/release/extenddb manage --user admin list-accounts -./target/release/extenddb manage --user admin \ - create-user --account-id --user-name quickstart -./target/release/extenddb manage --user admin \ - put-user-policy --account-id --user-name quickstart \ - --policy-name FullAccess \ - --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"dynamodb:*","Resource":"*"}]}' -./target/release/extenddb manage --user admin \ - create-access-key --account-id --user-name quickstart +Then run the rest: + +```sh +ACCOUNT_ID=$(./target/release/extenddb manage --user admin \ + list-accounts | grep -o '[0-9]\{12\}' | head -n 1) +./target/release/extenddb manage --user admin create-user \ + --account-id "$ACCOUNT_ID" --user-name dev +./target/release/extenddb manage --user admin put-user-policy \ + --account-id "$ACCOUNT_ID" --user-name dev \ + --policy-name DynamoDBAll \ + --policy-document '{"Version":"2012-10-17","Statement":[ + {"Effect":"Allow","Action":"dynamodb:*","Resource":"*"}]}' +./target/release/extenddb manage --user admin create-access-key \ + --account-id "$ACCOUNT_ID" --user-name dev unset EXTENDDB_PASSWORD +``` -# Set the access_key_id and secret_access_key that create-access-key printed -export AWS_ACCESS_KEY_ID= -export AWS_SECRET_ACCESS_KEY= -aws dynamodb list-tables --endpoint-url https://127.0.0.1:18443 --region us-east-1 +**4. Point the AWS CLI at it.** Run this line on its own. `aws configure` asks for the `access_key_id` and `secret_access_key` that `create-access-key` printed; answer `us-east-1` for the region, and press Enter at the output format. + +```sh +aws configure --profile extenddb ``` -See [Getting Started](docs/getting-started.md) for the full walkthrough, or use the platform installer scripts: +Then run the rest. AWS keys set in the shell override the profile, so the first line clears them. The server accepts only requests signed for its region, `us-east-1` unless `extenddb.toml` sets another, so the second line pins it. The last line trusts the self-signed certificate and turns off the CLI pager. -```bash -scripts/install-linux.sh # Linux -scripts/install-macos.sh # macOS +```sh +unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN +export AWS_PROFILE=extenddb AWS_REGION=us-east-1 +export AWS_CA_BUNDLE=~/.extenddb/tls/cert.pem AWS_PAGER="" ``` -## Prerequisites +**5. Create a table and use it.** A new table starts in `CREATING`, and a write before it is `ACTIVE` gets `ResourceNotFoundException`, so wait for it first. + +```sh +aws dynamodb create-table --endpoint-url https://127.0.0.1:18443 \ + --table-name Music \ + --attribute-definitions AttributeName=Artist,AttributeType=S \ + AttributeName=SongTitle,AttributeType=S \ + --key-schema AttributeName=Artist,KeyType=HASH \ + AttributeName=SongTitle,KeyType=RANGE \ + --billing-mode PAY_PER_REQUEST +aws dynamodb wait table-exists --endpoint-url https://127.0.0.1:18443 \ + --table-name Music +aws dynamodb put-item --endpoint-url https://127.0.0.1:18443 \ + --table-name Music \ + --item '{"Artist": {"S": "No One You Know"}, + "SongTitle": {"S": "Call Me Today"}, + "Year": {"N": "2025"}}' +aws dynamodb get-item --endpoint-url https://127.0.0.1:18443 \ + --table-name Music \ + --key '{"Artist": {"S": "No One You Know"}, + "SongTitle": {"S": "Call Me Today"}}' +``` -- Rust 1.94.0+ (`rustup update`) -- Python 3.10+ (for test suites and documentation) -- A storage backend: - - PostgreSQL 14+ (see `docs/local-postgres-setup.md`) - - SQLite (embedded) - - MongoDB 7+ (see `docs/local-mongodb-setup.md`) - - Cassandra 4.1+ (see `docs/cassandra-setup.md`) +`get-item` prints the item shown at the top of this page. An AWS SDK takes the same endpoint, region, key and certificate. [Getting Started](docs/getting-started.md) covers the other backends and the web console, and [`samples/`](samples/) has Python examples. -### Python Environment +Stop the server with `./target/release/extenddb stop`. To undo step 4, run `unset AWS_PROFILE AWS_REGION AWS_CA_BUNDLE AWS_PAGER`; the `extenddb` profile stays in `~/.aws/` until you delete it. -```bash -python3 -m venv ~/venvs/extenddb-venv -source ~/venvs/extenddb-venv/bin/activate -pip install -r requirements.txt -``` +On SQLite, PostgreSQL and MongoDB, `./target/release/extenddb destroy --yes` deletes the databases. It leaves `extenddb.toml`, the backup store and `~/.extenddb/`. -## Authentication Modes +- **SQLite:** `destroy` deletes `extenddb.sqlite` and its `-wal` and `-shm` files. It leaves the `.lock` file and the copies that `migrate --yes` makes, one for each run that applies a migration, named `extenddb.sqlite.pre-migration--to--