drizzle-team / drizzle-team/drizzle-orm

[BUG]: Re arrange table migration

Open
#1,433 2 comments 0 reactions 0 assignees View on GitHub
bug drizzle/kit
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

![Screenshot_20231028_171535](https://github.com/drizzle-team/drizzle-orm/assets/75155697/399c980c-7299-4451-a56d-cc62cdf4d27b)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.