drizzle-team / drizzle-team/drizzle-orm
[BUG]: Drizzle edits timestamp fields and recreates FK constraints when migrating from prisma
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.30.7
### What version of `drizzle-kit` are you using?
0.20.14
### Describe the Bug
1. Have an existing database generated by prisma
2. Have a db column that has `Json[]` type
3. Install Drizzle
4. Run `drizzle-kit introspect:pg`
5. Drizzle generates initial migration (one column should have `unknown().arra()` column type)
6. Fix it to `json().array()`
7. Run `drizzle-kit generate:pg`
Drizzle kit generates a new migrations altering **all** `createdAt` and `updatedAt` columns to
```sql
ALTER TABLE "{tableName}" ALTER COLUMN "{updatedAt or createdAt}" SET DEFAULT now();--> statement-breakpoint
```
Drizzle kit also drops **all** FK constraints and then recreates them
```sql
ALTER TABLE "{tableName}" DROP CONSTRAINT "{fKeyConstraintName}";
DO $$ BEGIN
ALTER TABLE "{tableName}" ADD CONSTRAINT "{differentFKeyConstraint" FOREIGN KEY ("{column}") REFERENCES "{table}"("{column}") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
```
The generated migration has about 700 LOC so it would be tedious to check if all constraints are not valid and it doesn't mess up something.
### Expected behavior
It shouldn't create any migration since i haven't changed anything
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.