> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chartdb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Import Cloudflare D1

> Import your Cloudflare D1 database schema into ChartDB

## Download Import Script

Download our Cloudflare D1 import script:

```bash theme={null}
curl -O https://app.chartdb.io/bash-scripts/cloudflare-d1-import.sh
chmod +x cloudflare-d1-import.sh
```

## Usage

Run the script with your Cloudflare D1 database name and ChartDB information:

```bash theme={null}
./cloudflare-d1-import.sh \
  -d your-database-name \
  -a your-chartdb-api-key \
  -t your-diagram-id
```

For remote databases, add the `-r` flag:

```bash theme={null}
./cloudflare-d1-import.sh \
  -d your-database-name \
  -a your-chartdb-api-key \
  -t your-diagram-id \
  -r
```

### Required Parameters

* `-d` Cloudflare D1 database name
* `-a` ChartDB API key
* `-t` Target diagram ID

### Optional Parameters

* `-r` Use remote database (if not specified, uses local database)

The script will connect to your Cloudflare D1 database, extract the schema, and automatically import it into your ChartDB diagram.

## Automated Daily Updates

To automatically update your diagram daily using cron, add the following line to your crontab:

```bash theme={null}
# Run at 2 AM every day
0 2 * * * /path/to/cloudflare-d1-import.sh -d database_name -a api_key -t diagram_id >> /path/to/d1-import.log 2>&1
```

To edit your crontab:

```bash theme={null}
crontab -e
```

<Note>
  **Note:** Replace `/path/to/cloudflare-d1-import.sh` with the absolute path to
  the script and adjust the database name accordingly. The log file path
  (`/path/to/d1-import.log`) should be in a directory where your user has write
  permissions.
</Note>
