Artur-Sulej / excellent_migrations

An Elixir tool for checking safety of database migrations.
MIT License
232 stars 25 forks source link

add_check_column_generated_stored #42

Open dkuku opened 3 days ago

dkuku commented 3 days ago

I hit this today: ecto allows to add a generated column.

alter table("posts") do
  add :identity, :integer, generated: "BY DEFAULT AS IDENTITY" # Postgres generated identity column
  add :generated_psql, :string, generated: "ALWAYS AS (id::text) STORED" # Postgres calculated column
  add :generated_other, :string, generated: "CAST(id AS char)" # MySQL and TDS calculated column
end

There are 2 types of generated columns but postgres only supports stored which calculates all the values during migration and locks the table. This is not safe on an existing table.