@netlify/agent-runner-cli 1.100.1 → 1.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: general-database
|
|
3
|
-
description: Use this skill whenever the task involves storing, persisting, querying, or managing data — including CRUD operations, collections, records, user data, or any application state that needs to survive between requests. Covers both relational databases (Netlify
|
|
3
|
+
description: Use this skill whenever the task involves storing, persisting, querying, or managing data — including CRUD operations, collections, records, user data, or any application state that needs to survive between requests. Covers both relational databases (Netlify Database) and key-value storage (Netlify Blobs).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Data Storage on Netlify
|
|
7
7
|
|
|
8
|
-
## Relational data: Netlify
|
|
8
|
+
## Relational data: Netlify Database
|
|
9
9
|
|
|
10
|
-
**Netlify
|
|
11
|
-
with zero configuration — install the `@netlify/
|
|
10
|
+
**Netlify Database** is the recommended solution for relational data storage. It provides a fully managed Postgres database
|
|
11
|
+
with zero configuration — install the `@netlify/database` package, and a database is automatically provisioned for your site.
|
|
12
12
|
|
|
13
|
-
Use Netlify
|
|
13
|
+
Use Netlify Database when you need:
|
|
14
14
|
|
|
15
15
|
- Relational data (tables, joins, foreign keys)
|
|
16
16
|
- SQL queries and filtering
|
|
@@ -19,25 +19,24 @@ Use Netlify DB when you need:
|
|
|
19
19
|
|
|
20
20
|
There are two recommended approaches:
|
|
21
21
|
|
|
22
|
-
- **Drizzle ORM** (recommended): Use Drizzle ORM with the native Netlify
|
|
23
|
-
and a query builder. Install `@netlify/
|
|
24
|
-
`
|
|
25
|
-
- **Native `@netlify/
|
|
22
|
+
- **Drizzle ORM** (recommended): Use Drizzle ORM with the native Netlify Database adapter for type-safe schema
|
|
23
|
+
definitions and a query builder. Install `@netlify/database`, `drizzle-orm@beta`, and `drizzle-kit@beta`. The
|
|
24
|
+
`@beta` dist-tag is required — the Netlify Database adapter only exists on the beta release line.
|
|
25
|
+
- **Native `@netlify/database` driver**: Use the `sql` tagged template literal for direct SQL queries. Install `@netlify/database`.
|
|
26
26
|
|
|
27
27
|
IMPORTANT: Any code that assumes a different database schema requires a corresponding migration file in
|
|
28
|
-
`netlify/
|
|
28
|
+
`netlify/database/migrations/`. Without a migration, the database schema will not change and the application will break.
|
|
29
29
|
|
|
30
|
-
See the **netlify-
|
|
30
|
+
See the **netlify-database** skill for complete setup instructions and usage examples.
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Object storage: Netlify Blobs
|
|
33
33
|
|
|
34
|
-
**Netlify Blobs** is the recommended solution for
|
|
34
|
+
**Netlify Blobs** is the recommended solution for object storage.
|
|
35
35
|
|
|
36
36
|
Use Netlify Blobs when you need:
|
|
37
37
|
|
|
38
38
|
- File and image storage
|
|
39
39
|
- JSON document persistence
|
|
40
40
|
- Cache storage
|
|
41
|
-
- Simple key-value data that doesn't require relational queries
|
|
42
41
|
|
|
43
42
|
See the **netlify-blobs** skill for complete setup instructions and usage examples.
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: netlify-
|
|
3
|
-
description: Use Netlify
|
|
2
|
+
name: netlify-database
|
|
3
|
+
description: Use Netlify Database for relational data storage with a fully managed Postgres database. Use when implementing data models with tables, relationships, SQL queries, transactions, or any data that benefits from a relational schema.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Netlify
|
|
6
|
+
# Netlify Database
|
|
7
7
|
|
|
8
|
-
Netlify
|
|
9
|
-
and database branching automatically. There is no setup beyond installing the `@netlify/
|
|
8
|
+
Netlify Database is a fully managed Postgres database built into the Netlify platform. It handles provisioning, migrations,
|
|
9
|
+
and database branching automatically. There is no setup beyond installing the `@netlify/database` package.
|
|
10
10
|
|
|
11
|
-
Prefer Netlify
|
|
11
|
+
Prefer Netlify Database over Netlify Blobs when the data is relational or requires SQL queries, unless the user explicitly
|
|
12
12
|
asks for a different storage solution.
|
|
13
13
|
|
|
14
|
-
## CRITICAL:
|
|
14
|
+
## CRITICAL: Use the `@beta` dist-tag for Drizzle
|
|
15
15
|
|
|
16
|
-
The
|
|
17
|
-
|
|
16
|
+
The Netlify Database adapter for Drizzle ORM only exists on the `beta` release line of `drizzle-orm`. You MUST install
|
|
17
|
+
both `drizzle-orm` and `drizzle-kit` from the `@beta` dist-tag — the default `latest` versions do not include the
|
|
18
|
+
Netlify Database adapter and will fail.
|
|
18
19
|
|
|
19
20
|
This affects:
|
|
20
|
-
- `npm install` commands:
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
- `npm install` commands: always install `drizzle-orm@beta` and `drizzle-kit@beta` (never `drizzle-orm` or
|
|
22
|
+
`drizzle-kit` without the tag).
|
|
23
|
+
- Import paths: use `drizzle-orm`, `drizzle-orm/pg-core`, and `drizzle-orm/netlify-db` as normal. No package
|
|
24
|
+
name rewriting is needed — the `@beta` tag only affects the installed version, not the imports.
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
If you forget the `@beta` tag, `drizzle-kit generate` will error with a message about being outdated, or the
|
|
27
|
+
`drizzle-orm/netlify-db` import will fail to resolve.
|
|
25
28
|
|
|
26
29
|
## CRITICAL: Database schema changes always require migrations
|
|
27
30
|
|
|
28
31
|
Any code change that assumes a different database schema (adding tables, adding columns, renaming fields, changing types,
|
|
29
|
-
adding indexes, etc.) will only work if a corresponding migration exists in `netlify/
|
|
32
|
+
adding indexes, etc.) will only work if a corresponding migration exists in `netlify/database/migrations/`. Without a
|
|
30
33
|
migration, the database schema will not change and the application will break at runtime.
|
|
31
34
|
|
|
32
|
-
This applies regardless of whether you are using Drizzle ORM or the native `@netlify/
|
|
35
|
+
This applies regardless of whether you are using Drizzle ORM or the native `@netlify/database` driver:
|
|
33
36
|
- **With Drizzle ORM**: Update the schema definition, then run `npx drizzle-kit generate`
|
|
34
|
-
- **With native driver**: Write a new SQL migration file in `netlify/
|
|
37
|
+
- **With native driver**: Write a new SQL migration file in `netlify/database/migrations/`
|
|
35
38
|
|
|
36
39
|
Never consider a schema change complete without a corresponding migration file.
|
|
37
40
|
|
|
@@ -43,8 +46,8 @@ generation.
|
|
|
43
46
|
### Step 1: Install packages
|
|
44
47
|
|
|
45
48
|
```bash
|
|
46
|
-
npm install @netlify/
|
|
47
|
-
npm install -D drizzle-kit
|
|
49
|
+
npm install @netlify/database drizzle-orm@beta
|
|
50
|
+
npm install -D drizzle-kit@beta
|
|
48
51
|
```
|
|
49
52
|
|
|
50
53
|
### Step 2: Create the schema file
|
|
@@ -53,7 +56,7 @@ Create `db/schema.ts` at the project root. Define all your tables here using Dri
|
|
|
53
56
|
|
|
54
57
|
```typescript
|
|
55
58
|
// db/schema.ts
|
|
56
|
-
import { pgTable, serial, text, timestamp, integer } from "
|
|
59
|
+
import { pgTable, serial, text, timestamp, integer } from "drizzle-orm/pg-core";
|
|
57
60
|
|
|
58
61
|
export const users = pgTable("users", {
|
|
59
62
|
id: serial().primaryKey(),
|
|
@@ -80,11 +83,11 @@ The Drizzle column variable names can be camelCase.
|
|
|
80
83
|
|
|
81
84
|
### Step 3: Create the database client
|
|
82
85
|
|
|
83
|
-
Create `db/index.ts`. This file initializes the Drizzle client with the native Netlify
|
|
86
|
+
Create `db/index.ts`. This file initializes the Drizzle client with the native Netlify Database adapter.
|
|
84
87
|
|
|
85
88
|
```typescript
|
|
86
89
|
// db/index.ts
|
|
87
|
-
import { drizzle } from "
|
|
90
|
+
import { drizzle } from "drizzle-orm/netlify-db";
|
|
88
91
|
import * as schema from "./schema.js";
|
|
89
92
|
|
|
90
93
|
export const db = drizzle({ schema });
|
|
@@ -94,8 +97,8 @@ The connection is configured automatically — no connection string needed.
|
|
|
94
97
|
|
|
95
98
|
### Step 4: Configure Drizzle Kit
|
|
96
99
|
|
|
97
|
-
Create `drizzle.config.ts` at the project root. The `out` property MUST be set to `netlify/
|
|
98
|
-
to automatically apply migrations.
|
|
100
|
+
Create `drizzle.config.ts` at the project root. The `out` property MUST be set to `netlify/database/migrations` for
|
|
101
|
+
Netlify to automatically apply migrations.
|
|
99
102
|
|
|
100
103
|
```typescript
|
|
101
104
|
// drizzle.config.ts
|
|
@@ -104,20 +107,7 @@ import { defineConfig } from "drizzle-kit";
|
|
|
104
107
|
export default defineConfig({
|
|
105
108
|
dialect: "postgresql",
|
|
106
109
|
schema: "./db/schema.ts",
|
|
107
|
-
out: "netlify/
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Alternatively, use the helper:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { defineConfig } from "drizzle-kit";
|
|
115
|
-
import { withNetlifyDB } from "@netlify/db/drizzle";
|
|
116
|
-
|
|
117
|
-
export default defineConfig({
|
|
118
|
-
dialect: "postgresql",
|
|
119
|
-
schema: "./db/schema.ts",
|
|
120
|
-
...withNetlifyDB(),
|
|
110
|
+
out: "netlify/database/migrations",
|
|
121
111
|
});
|
|
122
112
|
```
|
|
123
113
|
|
|
@@ -129,7 +119,7 @@ Run this every time you change the schema:
|
|
|
129
119
|
npx drizzle-kit generate
|
|
130
120
|
```
|
|
131
121
|
|
|
132
|
-
This creates SQL migration files in `netlify/
|
|
122
|
+
This creates SQL migration files in `netlify/database/migrations/`. DO NOT manually edit the generated migration files.
|
|
133
123
|
DO NOT create the migrations directory manually — `drizzle-kit generate` creates it.
|
|
134
124
|
|
|
135
125
|
### Step 6: Use the database in functions
|
|
@@ -166,7 +156,7 @@ When adding columns, tables, or changing the schema in an existing project:
|
|
|
166
156
|
|
|
167
157
|
1. Update the Drizzle schema definition with your changes
|
|
168
158
|
2. Run `npx drizzle-kit generate` — this is REQUIRED, not optional
|
|
169
|
-
3. Verify new migration files appear in `netlify/
|
|
159
|
+
3. Verify new migration files appear in `netlify/database/migrations/`
|
|
170
160
|
4. Update any application code that uses the changed tables
|
|
171
161
|
|
|
172
162
|
Do NOT skip step 2. The database will not reflect your schema changes without a generated migration.
|
|
@@ -174,7 +164,7 @@ Do NOT skip step 2. The database will not reflect your schema changes without a
|
|
|
174
164
|
### Drizzle ORM query reference
|
|
175
165
|
|
|
176
166
|
```typescript
|
|
177
|
-
import { eq, desc, and, or, like, sql } from "
|
|
167
|
+
import { eq, desc, and, or, like, sql } from "drizzle-orm";
|
|
178
168
|
import { db } from "./db/index.js";
|
|
179
169
|
import { users, posts } from "./db/schema.js";
|
|
180
170
|
|
|
@@ -222,13 +212,13 @@ Use this when you prefer raw SQL or don't want Drizzle ORM.
|
|
|
222
212
|
### Install
|
|
223
213
|
|
|
224
214
|
```bash
|
|
225
|
-
npm install @netlify/
|
|
215
|
+
npm install @netlify/database
|
|
226
216
|
```
|
|
227
217
|
|
|
228
218
|
### Query with `db.sql`
|
|
229
219
|
|
|
230
220
|
```typescript
|
|
231
|
-
import { getDatabase } from "@netlify/
|
|
221
|
+
import { getDatabase } from "@netlify/database";
|
|
232
222
|
|
|
233
223
|
const db = getDatabase();
|
|
234
224
|
|
|
@@ -280,12 +270,12 @@ try {
|
|
|
280
270
|
|
|
281
271
|
### Write migrations manually
|
|
282
272
|
|
|
283
|
-
When using the native driver, write SQL migration files by hand in `netlify/
|
|
273
|
+
When using the native driver, write SQL migration files by hand in `netlify/database/migrations/`.
|
|
284
274
|
|
|
285
275
|
Each migration is a SQL file named `<number>_<slug>.sql`:
|
|
286
276
|
|
|
287
277
|
```
|
|
288
|
-
netlify/
|
|
278
|
+
netlify/database/migrations/
|
|
289
279
|
├── 001_create-users.sql
|
|
290
280
|
├── 002_add-posts.sql
|
|
291
281
|
└── 003_create-comments.sql
|
|
@@ -294,7 +284,7 @@ netlify/db/migrations/
|
|
|
294
284
|
Example migration:
|
|
295
285
|
|
|
296
286
|
```sql
|
|
297
|
-
-- netlify/
|
|
287
|
+
-- netlify/database/migrations/001_create-users.sql
|
|
298
288
|
CREATE TABLE users (
|
|
299
289
|
id SERIAL PRIMARY KEY,
|
|
300
290
|
name TEXT NOT NULL,
|
|
@@ -312,7 +302,7 @@ Rules for migration names:
|
|
|
312
302
|
## Migrations: how they work
|
|
313
303
|
|
|
314
304
|
IMPORTANT: You must NEVER apply migrations yourself. Your job is only to CREATE migration files — either by running
|
|
315
|
-
`npx drizzle-kit generate` (when using Drizzle ORM) or by writing SQL files in `netlify/
|
|
305
|
+
`npx drizzle-kit generate` (when using Drizzle ORM) or by writing SQL files in `netlify/database/migrations/` (when using
|
|
316
306
|
the native driver). The Netlify platform applies migrations automatically at the right point in the deploy lifecycle.
|
|
317
307
|
Do NOT run `drizzle-kit migrate`, `drizzle-kit push`, or execute migration SQL directly against the database.
|
|
318
308
|
|
|
@@ -321,7 +311,7 @@ Netlify applies migrations automatically during deploys:
|
|
|
321
311
|
- **Production deploys:** Applied immediately before the deploy is published. A failure blocks publishing.
|
|
322
312
|
- **Deploy previews:** Applied on every new deploy, immediately before it becomes available. A failure fails the deploy.
|
|
323
313
|
|
|
324
|
-
Migrations MUST be in `netlify/
|
|
314
|
+
Migrations MUST be in `netlify/database/migrations/` to be applied automatically.
|
|
325
315
|
|
|
326
316
|
Two formats are supported:
|
|
327
317
|
1. SQL files directly in the directory (e.g. `001_create-users.sql`)
|
|
@@ -338,15 +328,16 @@ Drizzle Kit generates migrations in the subdirectory format. Both formats can co
|
|
|
338
328
|
|
|
339
329
|
## Common mistakes to avoid
|
|
340
330
|
|
|
341
|
-
1. **Wrong migration output directory**: Drizzle Kit defaults to `drizzle/`. You MUST set
|
|
342
|
-
in `drizzle.config.ts
|
|
343
|
-
applied.
|
|
331
|
+
1. **Wrong migration output directory**: Drizzle Kit defaults to `drizzle/`. You MUST set
|
|
332
|
+
`out: "netlify/database/migrations"` in `drizzle.config.ts`. If migrations are in the wrong directory, they will not
|
|
333
|
+
be applied.
|
|
344
334
|
|
|
345
|
-
2. **
|
|
346
|
-
`drizzle-orm`
|
|
335
|
+
2. **Forgetting the `@beta` dist-tag**: The Netlify Database adapter only exists on `drizzle-orm@beta` and
|
|
336
|
+
`drizzle-kit@beta`. Installing `drizzle-orm` or `drizzle-kit` without the `@beta` tag pulls the `latest` releases,
|
|
337
|
+
which lack the adapter and will fail. Always install with `drizzle-orm@beta` and `drizzle-kit@beta`.
|
|
347
338
|
|
|
348
339
|
3. **NEVER skip migration generation after schema changes**: Any code that assumes a different database schema requires
|
|
349
|
-
a corresponding migration in `netlify/
|
|
340
|
+
a corresponding migration in `netlify/database/migrations/`. With Drizzle ORM, run `npx drizzle-kit generate` after
|
|
350
341
|
updating the schema definition. With the native driver, write a SQL migration file. Schema changes alone do
|
|
351
342
|
nothing — the migration files are what Netlify applies. The application WILL break without them.
|
|
352
343
|
|