Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,18 @@ await supabase.table(Books.table).insertAll([
]);
await supabase
.table(Books.table)
.update(BooksUpdate(inPrint: false).setPriceToNull())
.update(BooksUpdate(inPrint: false, price: null))
.where(Books.id.eq(1));
await supabase.table(Books.table).delete().where(Books.id.eq(1));
```

Several rows go through `insertAll()` and `upsertAll()` instead of a list passed to `insert()`.
Passing `null` to a parameter of `BooksInsert` or `BooksUpdate` leaves the column out of the
request, so the database default applies or the value stays unchanged. To write SQL `NULL`, use the
generated `set…ToNull()` methods, which only exist for nullable columns.
A column left out of only some of the rows passed to `insertAll()` or `upsertAll()` also gets its
default, where an untyped `insert()` of a list writes `NULL`. Use `set…ToNull()` on the rows that
should write `NULL`.
A parameter of `BooksInsert` or `BooksUpdate` that is left out leaves the column out of the
request, so the database default applies or the value stays unchanged. Passing `null` writes SQL
`NULL`, which only a nullable column accepts; the parameter of a column that is not nullable has a
non-nullable type. A column left out of only some of the rows passed to `insertAll()` or
`upsertAll()` also gets its default, where an untyped `insert()` of a list writes `NULL`. Pass
`null` in the rows that should write `NULL`.
Comment thread
spydon marked this conversation as resolved.
Resolved

An `update()` or `delete()` sends nothing until it says which rows it acts on, through `where()`
or, for every row in the table, `all()`; a bare `await` of it compiles but performs no request,
Expand Down Expand Up @@ -1079,7 +1079,7 @@ Anything chained directly after `update()` or `delete()` has to move after the `

The typed `insert()`, `insertAll()`, `upsert()` and `upsertAll()` no longer take `defaultToNull`.
A column left out of an inserted row always gets its database default, and SQL `NULL` is written
with the generated `set…ToNull()` methods. An upsert that merges into an existing row only updates
by passing `null` for the column. An upsert that merges into an existing row only updates
the columns the request sends, so a column left out of every row keeps its value. On `insert()` and
`upsert()` the parameter had no effect.

Expand All @@ -1095,13 +1095,40 @@ await supabase.table(Books.table).insertAll([
// After
await supabase.table(Books.table).insertAll([
BooksInsert(authorId: 2, title: 'Dune', price: 10),
BooksInsert(authorId: 3, title: 'Emma').setPriceToNull(),
BooksInsert(authorId: 3, title: 'Emma', price: null),
]);
```

`insert()` and `upsert()` on `from()` keep `defaultToNull`. `PostgrestTableRequest` has no
`defaultToNull` either: an executor sends a list payload with `Prefer: missing=default`.

#### Passing `null` to a generated `Insert` or `Update` type writes SQL `NULL`

A parameter of a generated `Insert` or `Update` type that is passed `null` now writes SQL `NULL`.
It used to leave the column out, and the `set…ToNull()` methods, which are removed, wrote `NULL`.
Leaving the argument out still leaves the column out. `copyWith()` and the generated function calls
with arguments that have a default follow the same rule.

```dart skip
// Before
await supabase
.table(Books.table)
.update(BooksUpdate(inPrint: false).setPriceToNull())
.where(Books.id.eq(1));
```

```dart
// After
await supabase
.table(Books.table)
.update(BooksUpdate(inPrint: false, price: null))
.where(Books.id.eq(1));
```

A call that passes a variable which can be `null` still compiles after regenerating, but now
writes `NULL` where it used to keep the stored value, also on an upsert. Check such calls, and
leave the argument out where the stored value should stay.

#### Transforms that sent a different request now throw or narrow

These used to compile and send something other than what was asked for:
Expand Down
Loading
Loading