drizzle-team / drizzle-team/drizzle-orm
[BUG]: Re arrange table migration
- 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.28.6
### What version of `drizzle-kit` are you using?
0.19.13
### Describe the Bug
How to re arrange table migration on drizzle push command?
the migrations looks like
```sql
INSERT INTO "examination" SELECT * FROM "__old_push_examination";
DROP TABLE `__old_push_examination`;
ALTER TABLE `examination_participant` RENAME TO `__old_push_examination_participant`;
CREATE TABLE `examination_participant` (
`examination_id` text NOT NULL,
`user_id` text NOT NULL,
`started_at` integer DEFAULT 0 NOT NULL,
PRIMARY KEY(`examination_id`, `user_id`),
FOREIGN KEY (`examination_id`) REFERENCES `examination`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
....
INSERT INTO "school" SELECT * FROM "__old_push_school";
DROP TABLE `__old_push_school`;
CREATE UNIQUE INDEX `school_name_unique` ON `school` (`name`);
ALTER TABLE `school_member` RENAME TO `__old_push_school_member`;
CREATE TABLE `school_member` (
`user_id` text NOT NULL,
`school_id` text NOT NULL,
`role` text NOT NULL,
PRIMARY KEY(`school_id`, `user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`school_id`) REFERENCES `school`(`id`) ON UPDATE no action ON DELETE cascade
);
```
so the table schema become like this, and it will error whenever insertion into `examination` table

does my drizzle schema deffinitions are wrong so the sql statement is broken, or this is a bug?
### Expected behavior
the `examination` table migration must be after `school` table
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.