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
9 changes: 0 additions & 9 deletions .changeset/mysql-generated-columns.md

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @maple-dev/effect-orm

## 1.1.0

### Minor Changes

- 05fbd7a: MySQL and MariaDB generated columns: `MySQL.column(type, { generated: { as, stored? } })` declares a `GENERATED ALWAYS AS (<as>) STORED | VIRTUAL` column. `as` is SQL, or a DSL callback that may read the row's columns. The column is computed, as a ClickHouse `MATERIALIZED` one is: an insert row, an update SET or `onDuplicateKeyUpdate` that writes it is a type error and refused at runtime, `excludedAll` skips it, and `tableSchemas(table).insert` / `.update` leave it out; selects read it. It works on `external: true` tables, where it only marks the column computed, so an insert into a table another tool owns no longer sends a column MySQL refuses.

On an owned table the DDL writes `` `col` <type> GENERATED ALWAYS AS (<expr>) STORED|VIRTUAL `` with no `NOT NULL` (MariaDB refuses it there) and no default, so declare `MySQL.nullable(...)` unless the expression cannot be NULL. Definition problems: a `default`, `defaultExpr`, `defaultFn` or `onUpdate` beside it (also a type error), an empty `as`, a generated primary key or tenant column, and, for a callback only, one that reads itself, a generated column declared after it, or a nullable column into a non-nullable type. A string `as` is not checked.

`effect-orm generate` creates and adds such columns (a new generated one `AFTER` the column before it), and `MODIFY`s a changed expression or type, and a base column made STORED (which needs `confirm_data_loss`) or a STORED one made base (which keeps its values). A column made VIRTUAL, or a VIRTUAL one made STORED or base, is dropped and added back in one `ALTER TABLE`, in its place and with its indexes around it; to or from base needs `confirm_data_loss`, and a VIRTUAL column made base under a UNIQUE key is refused as unsupported. The ops are ordered around what generated columns read: base columns are added first and generated ones dropped first, and the generated columns reading a column that is renamed or dropped and added back (including ones renamed or replaced themselves) are dropped before it, last declared first, and added back after in declaration order. `MySQL.ComputedColumnsOf` and `MySQL.GeneratedColumn` are new types, and `MysqlSchemaTable` takes the computed columns as a new last type parameter. `MysqlColumnEntity` has an optional `generated: { expr, stored, reads? }` (`reads`: the columns a callback read), absent on other columns, so existing snapshots keep their ids. `MysqlMigrationOp` has a `replace_column` op, and `add_column` an optional `after`.

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maple-dev/effect-orm",
"version": "1.0.0",
"version": "1.1.0",
"description": "Type-safe ClickHouse, Postgres, SQLite and MySQL queries, result decoding, and reproducible benchmarks for Effect and TypeScript",
"keywords": [
"clickhouse",
Expand Down