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: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function PostList() {
### Customize with `drizzle-zero.config.ts`

If you want to customize the tables/columns that are synced by Zero, you can optionally
create a new config file at `drizzle-zero.config.ts` specifying the columns you want to
create a new config file at `drizzle-zero.config.ts` specifying the tables and/or columns you want to
include in the CLI output:

```ts
Expand All @@ -154,17 +154,16 @@ import * as drizzleSchema from "./drizzle-schema";
export default drizzleZeroConfig(drizzleSchema, {
// Specify which tables and columns to include in the Zero schema.
// This allows for the "expand/migrate/contract" pattern recommended in the Zero docs.
// When a column is first added, it should be set to false, and then changed to true
// once the migration has been run.

// All tables/columns must be defined, but can be set to false to exclude them from the Zero schema.
// All tables/columns must be defined, but can be omitted or set to false to exclude them from the Zero schema.
// Column names match your Drizzle schema definitions
tables: {
// this can be set to false
// e.g. user: false,
// e.g. users: false,
users: {
id: true,
name: true,
// omit columns to exclude them
email: true,
},
posts: {
Expand Down
50 changes: 2 additions & 48 deletions integration/drizzle-zero.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,8 @@ export const schema = drizzleZeroConfig(drizzleSchema, {
body: true,
metadata: true,
},
allTypes: {
id: true,
createdAt: true,
updatedAt: true,
smallintField: true,
integerField: true,
bigintField: true,
bigintNumberField: true,
smallSerialField: true,
serialField: true,
bigSerialField: true,
numericField: true,
decimalField: true,
realField: true,
doublePrecisionField: true,
textField: true,
charField: true,
uuidField: true,
varcharField: true,
booleanField: true,
timestampField: true,
timestampTzField: true,
timestampModeDate: true,
timestampModeString: true,
dateField: true,
jsonField: true,
jsonbField: true,
typedJsonField: true,
statusField: true,
optionalSmallint: true,
optionalInteger: true,
optionalBigint: true,
optionalNumeric: true,
optionalReal: true,
optionalDoublePrecision: true,
optionalText: true,
optionalBoolean: true,
optionalTimestamp: true,
optionalJson: true,
optionalEnum: true,
optionalVarchar: true,
optionalUuid: true,
},
friendship: {
acceptingId: true,
requestingId: true,
accepted: true,
},
allTypes: true,
friendship: true,
filters: {
id: true,
name: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ CREATE TABLE "message" (
"senderId" text,
"mediumId" text,
"body" text NOT NULL,
"metadata" jsonb NOT NULL
"metadata" jsonb NOT NULL,
"omitted_column" text
);
--> statement-breakpoint
CREATE TABLE "omitted_table" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user" (
Expand Down
78 changes: 66 additions & 12 deletions integration/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "81e34413-4954-4b23-a110-628dfe74737f",
"id": "34d17a8e-0f49-4f66-97fb-fb384c311e71",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -327,25 +327,36 @@
"name": "friendship_requesting_id_user_id_fk",
"tableFrom": "friendship",
"tableTo": "user",
"columnsFrom": ["requesting_id"],
"columnsTo": ["id"],
"columnsFrom": [
"requesting_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"friendship_accepting_id_user_id_fk": {
"name": "friendship_accepting_id_user_id_fk",
"tableFrom": "friendship",
"tableTo": "user",
"columnsFrom": ["accepting_id"],
"columnsTo": ["id"],
"columnsFrom": [
"accepting_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"friendship_requesting_id_accepting_id_pk": {
"name": "friendship_requesting_id_accepting_id_pk",
"columns": ["requesting_id", "accepting_id"]
"columns": [
"requesting_id",
"accepting_id"
]
}
},
"uniqueConstraints": {},
Expand Down Expand Up @@ -439,6 +450,12 @@
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"omitted_column": {
"name": "omitted_column",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
Expand All @@ -447,17 +464,25 @@
"name": "message_senderId_user_id_fk",
"tableFrom": "message",
"tableTo": "user",
"columnsFrom": ["senderId"],
"columnsTo": ["id"],
"columnsFrom": [
"senderId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"message_mediumId_medium_id_fk": {
"name": "message_mediumId_medium_id_fk",
"tableFrom": "message",
"tableTo": "medium",
"columnsFrom": ["mediumId"],
"columnsTo": ["id"],
"columnsFrom": [
"mediumId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
Expand All @@ -468,6 +493,31 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.omitted_table": {
"name": "omitted_table",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
Expand Down Expand Up @@ -554,7 +604,11 @@
"public.status_type": {
"name": "status_type",
"schema": "public",
"values": ["active", "inactive", "pending"]
"values": [
"active",
"inactive",
"pending"
]
}
},
"schemas": {},
Expand All @@ -567,4 +621,4 @@
"schemas": {},
"tables": {}
}
}
}
6 changes: 3 additions & 3 deletions integration/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
{
"idx": 0,
"version": "7",
"when": 1745621570511,
"tag": "0000_warm_photon",
"when": 1752621276580,
"tag": "0000_amazing_husk",
"breakpoints": true
}
]
}
}
6 changes: 6 additions & 0 deletions integration/drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const message = pgTable("message", {
mediumId: text("mediumId").references(() => medium.id),
body: text("body").notNull(),
metadata: jsonb("metadata").$type<{ key: string }>().notNull(),
omittedColumn: text("omitted_column"),
});

export const messageRelations = relations(message, ({ one }) => ({
Expand Down Expand Up @@ -191,3 +192,8 @@ export const filtersRelations = relations(filters, ({ one, many }) => ({
}),
children: many(filters),
}));

export const omittedTable = pgTable("omitted_table", {
id: text("id").primaryKey(),
name: text("name").notNull(),
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-zero",
"version": "0.12.1",
"version": "0.13.0",
"description": "Generate Zero schemas from Drizzle ORM schemas",
"type": "module",
"scripts": {
Expand Down
Loading