drizzle-team / drizzle-team/drizzle-orm
[BUG]: `readMigrationFiles` (drizzle-orm/migrator) Inconsistent SQL Migration Files Processing Across Different Operating Systems
- 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.41.0
### What version of `drizzle-kit` are you using?
0.30.1
### Other packages
_No response_
### Describe the Bug
## Description
When using the `readMigrationFiles` function from `drizzle-orm/migrator`, the generated SQL arrays differ between Windows and macOS/Linux environments due to different line ending conventions.
## Current Behavior
The `readMigrationFiles` function reads SQL files and splits them at statement breakpoints. However, it preserves the native line endings:
- On Windows: Lines end with `\r\n` (CRLF)
- On macOS/Linux: Lines end with `\n` (LF)
This causes inconsistency in the resulting SQL arrays:
**On macOS:**
```json
"sql": [
"ALTER TABLE \"messages\" ADD COLUMN \"client_id\" text;",
"\nALTER TABLE \"session_groups\" ADD COLUMN \"client_id\" text;",
// ...more statements with \n line breaks
]
```
**On Windows:**
```json
"sql": [
"ALTER TABLE \"messages\" ADD COLUMN \"client_id\" text;",
"\r\nALTER TABLE \"session_groups\" ADD COLUMN \"client_id\" text;",
// ...more statements with \r\n line breaks
]
```
## Expected Behavior
The function should produce consistent SQL arrays regardless of the operating system where it runs.
## Proposed Solution
Normalize line endings when reading SQL files:
```typescript
const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`)
.toString()
.replace(/\r\n/g, '\n'); // Normalize all line endings to LF
```
This simple change ensures consistent behavior across all platforms.
Contributor guide
Assessment
This issue has not been assessed yet.