@everystack/model 0.3.4 → 0.3.5

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.
package/README.md CHANGED
@@ -74,6 +74,8 @@ export const models = [Account, Note];
74
74
 
75
75
  Modifiers: `.primaryKey()`, `.notNull()` / `.nullable()`, `.unique()`, `.default(value)` / `.defaultNow()` / `.defaultRandom()`, `.references(() => Other, { onDelete, onUpdate })`, `.private()` (never serialized), `.readonly()` (never accepted on write), `.validate(zodSchema)`, and `.renamedFrom('oldField')` (turns a drop+add into a data-preserving `RENAME COLUMN`).
76
76
 
77
+ Renaming a whole table works the same way, at the model level: `defineModel('articles', { renamedFrom: 'posts', ... })` compiles to one `ALTER TABLE … RENAME TO …` (data preserved, policies ride along) instead of CREATE plus a held DROP. Both markers are one-shot — remove them once every environment is past the state; a satisfied rename is an inert notice.
78
+
77
79
  `.validate(...)` does double duty: the SQL-expressible refinements (`min`/`max`/`length`/range/enum) become a Postgres `CHECK` — the backstop for the SSR-direct write path that never runs app-layer Zod — while richer refinements stay app-layer only.
78
80
 
79
81
  ## Constraints
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everystack/model",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Declare a table's schema, validation, and authorization once — compiled to migrations, RLS, and handler config",
5
5
  "license": "AGPL-3.0-only",
6
6
  "publishConfig": {
package/src/model.ts CHANGED
@@ -63,6 +63,15 @@ export interface ModelDefinition {
63
63
  * can span schemas — the model's schema always wins over a generate call's default.
64
64
  */
65
65
  schema?: string;
66
+ /**
67
+ * `renamedFrom: 'old_table'` — a one-shot migration hint, the table-level
68
+ * analog of `field.renamedFrom()`. A diff cannot distinguish RENAME from
69
+ * DROP+ADD; the marker carries the intent, so the diff emits one
70
+ * `ALTER TABLE … RENAME TO …` (data preserved) instead of CREATE plus a
71
+ * held DROP. Same schema as the model. Remove it once every environment
72
+ * is past the state — a satisfied rename is an inert notice.
73
+ */
74
+ renamedFrom?: string;
66
75
  /**
67
76
  * `true` removes the table from the generic data API — `deriveHandlerConfig`
68
77
  * skips it, so it never enters `exposedTables`. Default `false`. Package-owned
@@ -90,6 +99,8 @@ export interface ModelDescriptor {
90
99
  schema: string;
91
100
  /** `true` removes the table from the generic data API (not in `exposedTables`). Default `false`. */
92
101
  private: boolean;
102
+ /** One-shot rename hint: this table used to be named `renamedFrom` (same schema). */
103
+ renamedFrom?: string;
93
104
  }
94
105
 
95
106
  export function defineModel(table: string, def: ModelDefinition): ModelDescriptor {
@@ -108,5 +119,6 @@ export function defineModel(table: string, def: ModelDefinition): ModelDescripto
108
119
  writtenBy: def.writtenBy ?? 'app',
109
120
  schema: def.schema ?? 'public',
110
121
  private: def.private ?? false,
122
+ ...(def.renamedFrom ? { renamedFrom: def.renamedFrom } : {}),
111
123
  };
112
124
  }