Skip to content

fix: Inconsistent SQL Migration Files Processing Across Different Operating Systems #4331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

canisminor1990
Copy link

Description

When using the readMigrationFiles function, 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:

"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:

"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:

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.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant