durcno@1.0.0-alpha.7
Minor Changes
-
c79fe01 - Thanks to @almahdi404 !
impr(migration)!: emit check constraints as builder callbacks in generated migrations
Previously, check constraints in generated migration files were serialized as raw JSON expression objects (
{"type":"comparison",...}), which was unreadable and inconsistent with the schema definition API.Migration files now emit check constraints using the same callback pattern as the schema definition, with
sqltemplate literals for literal values:// Beforecheck("positive_price", {type: "comparison",left: { type: "col", name: "price" },op: ">",right: "0",});// Aftercheck("positive_price", ({ gt }) => gt("price", sql`0`));check("valid_qty", ({ and, gte, lte }) =>and(gte("quantity", sql`0`), lte("quantity", sql`10000`)),);check("valid_email", ({ like }) => like("email", sql`'%@%.%'`));check("name_length", ({ and, fnGt, fnLte, length }) =>and(fnGt(length("user_name"), sql`2`),fnLte(length("user_name"), sql`100`),),);The
inoperator is safely aliased asinOpin the destructuring pattern, sinceinis a JS reserved word.New exports from
durcno/migration:sql— the SQL template literal tag, for use in migration check expressionsMigrationCheckBuilder— the builder class whose methods are passed via the callback
check()/addCheck()only accept the callback form. Passing a rawSnapshotCheckExprobject directly is no longer supported.