Skip to content

Commit 54b6648

Browse files
authored
fix: use PostgreSQL identity columns with drizzle (#2002)
1 parent fe85a23 commit 54b6648

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.changeset/red-bags-beam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-t3-app": minor
3+
---
4+
5+
Change drizzle with PostgresQL to use identity columns

cli/template/extras/src/server/db/schema-drizzle/base-postgres.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import { sql } from "drizzle-orm";
55
import {
66
index,
7+
integer,
78
pgTableCreator,
8-
serial,
99
timestamp,
1010
varchar,
1111
} from "drizzle-orm/pg-core";
@@ -21,7 +21,7 @@ export const createTable = pgTableCreator((name) => `project1_${name}`);
2121
export const posts = createTable(
2222
"post",
2323
{
24-
id: serial("id").primaryKey(),
24+
id: integer("id").primaryKey().generatedByDefaultAsIdentity(),
2525
name: varchar("name", { length: 256 }),
2626
createdAt: timestamp("created_at", { withTimezone: true })
2727
.default(sql`CURRENT_TIMESTAMP`)

cli/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
integer,
55
pgTableCreator,
66
primaryKey,
7-
serial,
87
text,
98
timestamp,
109
varchar,
@@ -22,7 +21,7 @@ export const createTable = pgTableCreator((name) => `project1_${name}`);
2221
export const posts = createTable(
2322
"post",
2423
{
25-
id: serial("id").primaryKey(),
24+
id: integer("id").primaryKey().generatedByDefaultAsIdentity(),
2625
name: varchar("name", { length: 256 }),
2726
createdById: varchar("created_by", { length: 255 })
2827
.notNull()

0 commit comments

Comments
 (0)