diff --git a/.changeset/red-bags-beam.md b/.changeset/red-bags-beam.md new file mode 100644 index 0000000000..ff67b9a048 --- /dev/null +++ b/.changeset/red-bags-beam.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": minor +--- + +Change drizzle with PostgresQL to use identity columns diff --git a/cli/template/extras/src/server/db/schema-drizzle/base-postgres.ts b/cli/template/extras/src/server/db/schema-drizzle/base-postgres.ts index 8e6f2f99e1..3878a981fd 100644 --- a/cli/template/extras/src/server/db/schema-drizzle/base-postgres.ts +++ b/cli/template/extras/src/server/db/schema-drizzle/base-postgres.ts @@ -4,8 +4,8 @@ import { sql } from "drizzle-orm"; import { index, + integer, pgTableCreator, - serial, timestamp, varchar, } from "drizzle-orm/pg-core"; @@ -21,7 +21,7 @@ export const createTable = pgTableCreator((name) => `project1_${name}`); export const posts = createTable( "post", { - id: serial("id").primaryKey(), + id: integer("id").primaryKey().generatedByDefaultAsIdentity(), name: varchar("name", { length: 256 }), createdAt: timestamp("created_at", { withTimezone: true }) .default(sql`CURRENT_TIMESTAMP`) diff --git a/cli/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts b/cli/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts index 5ce3f9c252..43e62439f7 100644 --- a/cli/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts +++ b/cli/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts @@ -4,7 +4,6 @@ import { integer, pgTableCreator, primaryKey, - serial, text, timestamp, varchar, @@ -22,7 +21,7 @@ export const createTable = pgTableCreator((name) => `project1_${name}`); export const posts = createTable( "post", { - id: serial("id").primaryKey(), + id: integer("id").primaryKey().generatedByDefaultAsIdentity(), name: varchar("name", { length: 256 }), createdById: varchar("created_by", { length: 255 }) .notNull()