Skip to content

fix(mysql): Fix Sequential Migration Failures#1153

Open
eduardomozart wants to merge 12 commits intognmyt:mainfrom
eduardomozart:patch-3
Open

fix(mysql): Fix Sequential Migration Failures#1153
eduardomozart wants to merge 12 commits intognmyt:mainfrom
eduardomozart:patch-3

Conversation

@eduardomozart
Copy link
Copy Markdown
Contributor

@eduardomozart eduardomozart commented Feb 20, 2026

📋 Description

All modified migration files retain 100% functionality for existing SQLite users.

0006-update-organization-members-primary-key.js

  • Syntax Translation: Dynamically handle datetime functions based on the database dialect. The current codebase contained SQLite-specific raw SQL syntax that caused fatal errors when attempting to run on a MySQL or MariaDB backend.
  • Deduplication Logic: Handled SQLite's hidden rowid dependency by making the HAVING MIN(rowid) clause conditional based on the database dialect. MariaDB uses a standard GROUP BY approach for data migration from backup tables.

0011-unified-schema-migration.js

The 0011-unified-schema-migration.js file relied on several raw SQL commands that are exclusive to SQLite. When running Nexterm with a MariaDB or MySQL backend, these commands caused the migration runner to crash, preventing the application from initializing. These changes allow the same migration file to work seamlessly across both database types.

  • Dialect Awareness: Added logic to detect the active database dialect (MySQL/MariaDB vs. SQLite) at the start of the migration.
  • Foreign Key Handling: Replaced SQLite-specific PRAGMA commands with SET FOREIGN_KEY_CHECKS for MySQL/MariaDB to safely toggle constraints during the migration.
  • Metadata Translation: Implemented a conditional check to use SHOW COLUMNS on MySQL/MariaDB instead of PRAGMA table_info when verifying existing table structures.
  • Identity & Date Functions: Dynamically switched between LAST_INSERT_ID()/NOW() for MySQL and last_insert_rowid()/datetime('now') for SQLite.
  • Column Alteration Syntax: Adjusted the ALTER TABLE syntax for adding integrationId to accommodate MySQL's requirement for explicit constraint definitions.

0012-add-tags.js, 0013-add-keymaps.js, 0014-add-session-sync.js, 0015-remove-app-sources.js, 0016-add-scripts.js, 0017-add-organization-to-snippets-and-scripts.js, 0020-add-passkeys.js, 0020-add-sort-order-to-snippets-and-scripts.js and 0027-add-preferences.js

  • Dialect Awareness: MariaDB and MySQL do not support PRAGMA commands; they use system variables like FOREIGN_KEY_CHECKS to control constraint behavior. This modification ensures that the migration script remains functional for users on the default SQLite setup while enabling successful execution on your MariaDB backend.

🚀 Changes made to ...

  • 🔧 Server
  • 🖥️ Client
  • 📚 Documentation
  • 🔄 Other: ___

✅ Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have looked for similar pull requests in the repository and found none
  • This pull request does not contain translations (translations are managed through Crowdin)

🔗 Related Issues

None.

@eduardomozart eduardomozart changed the title fix(mysql): Enable MariaDB/MySQL Support and Fix Sequential Migration Failures fix(mysql): Fix Sequential MariaDB/MySQL Migration Failures Feb 20, 2026
@eduardomozart eduardomozart changed the title fix(mysql): Fix Sequential MariaDB/MySQL Migration Failures fix(mysql): Fix Sequential Migration Failures Feb 20, 2026
Added conditional handling for foreign key checks based on the database dialect before dropping the 'app_sources' table.
Added conditional handling for foreign key checks based on the database dialect.
Add a 'preferences' column to the 'accounts' table with JSON type.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
12 Security Hotspots
8.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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