drizzle-team / drizzle-team/drizzle-orm
[BUG]: Drizzle creating identifiers with name greater than 63 bytes without warning (critical)
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0..38.4
### What version of `drizzle-kit` are you using?
0.30.2
### Other packages
_No response_
### Describe the Bug
## Undesired Behavior
As per this [documentation](https://www.postgresql.org/docs/current/limits.html) the limit for the length of an identifier in Postgres is 63 bytes. Anything larger is truncated by default. This is causing unexpected bugs in the DB.
I have a table that references another table . And the autogenerated identifier is longer than 63 bytes. This was the created SQL:
```sql
ALTER TABLE "myschema"."roles_myproject_gpt_assistants" ADD CONSTRAINT "roles_myproject_gpt_assistants_assistant_id_myproject_gpt_assistants_id_fk" FOREIGN KEY ("assistant_id") REFERENCES "myschema"."myproject_gpt_assistants"("id") ON DELETE no action ON UPDATE no action;
```
This identifier is greater than 63 bytes and the rest of the identifier is truncated and is causing multiple identifiers to have the same name.
## Steps to reproduce
1. Create a sample db having two tables with long names and long column names.
2. Create a foreign key relation between them.
## Environment I am on
PostgreSQL: 16
Driver: PotgresJs@3.4.5
Runtime: BunJs@1.2
## Expected Behavior
Drizzle shouldn't auto generated an identifier longer than 63 bytes without warning. Or add a random string (say `asX4ft_`) in front of the identifier by default if the name is not provided explicitly.
Contributor guide
Assessment
This issue has not been assessed yet.