Generates alter table statements for columns that haven't changed
See original GitHub issueBug description
Prisma generates alter table statements every time a migration is created (–create only) or applied prisma migrate dev
when a model attribute contains dbgenerated("myschema.uuid_generate_v4()")
How to reproduce
- Create the following schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = ""
}
model Account {
id String @id @default(dbgenerated("myschema.uuid_generate_v4()")) @db.Uuid
@@map(name: "accounts")
}
model Product {
id String @id @default(dbgenerated("myschema.uuid_generate_v4()")) @db.Uuid
@@map(name: "products")
}
- Run
prisma migrate dev --create-only
. - Manually update the migration to include:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA myschema VERSION "1.1";
. - Apply migration by running
prisma migrate dev
. - Prisma then generates a another migration.sql file with the following content:
-- AlterTable
ALTER TABLE "accounts" ALTER COLUMN "id" SET DEFAULT myschema.uuid_generate_v4();
-- AlterTable
ALTER TABLE "products" ALTER COLUMN "id" SET DEFAULT myschema.uuid_generate_v4();
- Add name attribute for the account model
model Account {
id String @id @default(dbgenerated("myschema.uuid_generate_v4()")) @db.Uuid
name String @db.VarChar(50)
@@map(name: "accounts")
}
- Apply the migration by running
prisma migrate dev
. - Prisma generates again the alter for the id attributes
-- AlterTable
ALTER TABLE "accounts" ADD COLUMN "name" VARCHAR(50) NOT NULL,
ALTER COLUMN "id" SET DEFAULT myschema.uuid_generate_v4();
-- AlterTable
ALTER TABLE "products" ALTER COLUMN "id" SET DEFAULT myschema.uuid_generate_v4();
Expected behavior
Not generate alter statements for the id columns since those haven’t change.
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = ""
}
model Account {
id String @id @default(dbgenerated("myschema.uuid_generate_v4()")) @db.Uuid
@@map(name: "accounts")
}
model Product {
id String @id @default(dbgenerated("myschema.uuid_generate_v4()")) @db.Uuid
@@map(name: "products")
}
Environment & setup
- OS: Mac OS Big Sur 11.4
- Database: PostgreSQL 13.2
- Node.js version: v12.20.0
Prisma Version
prisma : 2.24.1
@prisma/client : Not found
Current platform : darwin
Query Engine : query-engine 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 18095475d5ee64536e2f93995e48ad800737a9e4
Studio : 0.397.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to Alter Columns or Generate Alter Scripts by ... - YouTube
SQL Server / TSQL Tutorial Scenario: How to Alter Columns or Generate Alter Scripts by using GUI in SQL ServerYou have created a...
Read more >ALTER TABLE: a SQL statement for altering a database table
Existing tables can be altered with an ALTER TABLE statement. An ALTER TABLE ... That column currently does not have a NOT NULL...
Read more >How to Alter Columns or Generate Alter Scripts by using GUI ...
Step 1: Go to Database and then go to Tables tab. Once you see your required table, Right Click and hit Design. ......
Read more >Create table or only add changed/new columns - Stack Overflow
I have several tables which are worked on within a development environment, then moved to production. If they don't already exist in production, ......
Read more >Generate DDL - change is a new column and I want to ...
Here I would like to have the generate be aware the it needs only to generate an alter table add column and not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We need to find a user-friendlier way to deal with this, but glad the workaround worked for you 😃
@tomhoule Ah thank you. I peaked at the sql file and this is specifically what prisma generated:
date_trunc('month'::text, now())
. Updating my attribute to@default(dbgenerated("date_trunc('month'::text, now())"))
has fixed the issue for me.