drizzle-team / drizzle-team/drizzle-orm
[BUG]: Does `drizzle-orm` migration ignore `INSERT` statements?
- 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.36.4
### What version of `drizzle-kit` are you using?
0.28.1
### Other packages
_No response_
### Describe the Bug
Hello, drizzle-orm team! 👋
I’m using drizzle-orm with expo-sqlite to manage my database migrations, and I encountered an issue where `INSERT` statements in a migration file seem to be ignored during runtime.
## Problem Description
When running a migration generated by drizzle-kit that includes INSERT statements, only the table structure is created. The data from the INSERT statements is not being added to the table.
## Reproduction Steps
### 1. Generate a migration file using drizzle-kit generate.
```sql
-- 0000_rare_miss_america.sql
CREATE TABLE `category` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text NOT NULL,
`image` text,
`order` integer NOT NULL,
`isDisabled` integer DEFAULT 0 NOT NULL
);
-- statement-breakpoint
CREATE UNIQUE INDEX `category_name_unique` ON `category` (`name`);
```
### 2. Add the following INSERT statements manually for seed data:
```sql
-- 0000_rare_miss_america.sql
...
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 0, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 1, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 2, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 3, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 4, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 5, 0);
INSERT INTO `category` (`name`, `image`, `order`, `isDisabled`) VALUES ('***', '***', 6, 0);
```
### 3. Run the migration in the expo runtime environment.
### 4. Observe:
- The category table is successfully created.
- However, no rows from the INSERT statements are found in the table.
```typescript
db.select({ name: sql`name` })
.from(sql`sqlite_master`)
.execute()
.then((res) => {
console.log('Table Created?: ', JSON.stringify(res, null, 4)); // `category` table has been created ✅
});
```
## Questions
- Are INSERT statements ignored in drizzle-orm migrations by design?
- If so, what is the recommended way to seed initial data alongside migrations?
## Additional Details
- Environment:
- drizzle-orm version: 0.36.4
- drizzle-kit version: 0.28.1
- expo: 51.0.39
- expo-sqlite version: 14.0.6
- Database: SQLite
- Runtime: Expo
Thank you for your time and support! 😊
Contributor guide
Research direction
Start by reproducing the generated SQL migration in the Expo runtime with expo-sqlite, using the shown CREATE TABLE and INSERT statements. Inspect how the migration runner handles statement-breakpoint-separated SQL, and consider the issue resolved when the migration behavior for INSERT statements is reproduced, fixed, or clearly documented with the recommended seeding approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, sqlite, typescript
- Domain
- databases, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100