-
Notifications
You must be signed in to change notification settings - Fork 293
[DB] Partitioning refactor: Add partition_key column, unify logic across MySQL and Postgres #8347
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
Closed
adamdelman
wants to merge
205
commits into
mlrun:development
from
adamdelman:adamd/postgres_integration_test
Closed
[DB] Partitioning refactor: Add partition_key column, unify logic across MySQL and Postgres #8347
adamdelman
wants to merge
205
commits into
mlrun:development
from
adamdelman:adamd/postgres_integration_test
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…res_integration_test
…an/mlrun into adamd/postgres_integration_test
…res_integration_test
10 tasks
liranbg
added a commit
that referenced
this pull request
Jan 13, 2026
### 📝 Description Continuing the work done by @adamdelman @ #8347 --- This PR refactors and enhances the database partitioning system for alert activations to improve cross-database compatibility, robustness, and maintainability. The changes establish a cleaner architecture for partition management while adding full PostgreSQL support alongside the existing MySQL implementation. Key improvements: - Cross-database support: Added native PostgreSQL partitioning alongside MySQL, with SQLite gracefully skipping partition operations - Explicit partition keys: Introduced a dedicated partition_key integer column computed from activation_time, enabling consistent partitioning logic across databases - Partition metadata tracking: New table_partition_interval table persists partition configuration, decoupling interval choice from table structure - Improved bootstrapping: Separated partition creation logic into dedicated bootstrapper classes per database dialect - Enhanced testing: Comprehensive integration tests for both MySQL and PostgreSQL partition operations --- ### 🛠️ Changes Made - Integration tests now run against both mysql and postgres backends --- ### ✅ Checklist - [ ] I updated the documentation (if applicable) - [ ] I have tested the changes in this PR - [ ] I confirmed whether my changes are covered by system tests - [ ] If yes, I ran all relevant system tests and ensured they passed before submitting this PR - [ ] I updated existing system tests and/or added new ones if needed to cover my changes - [ ] If I introduced a deprecation: - [ ] I followed the [Deprecation Guidelines](./DEPRECATION.md) - [ ] I updated the relevant Jira ticket for documentation --- ### 🧪 Testing <!-- - How it was tested (unit tests, manual, integration) --> <!-- - Any special cases covered. --> --- ### 🔗 References - Ticket link: https://iguazio.atlassian.net/browse/ML-11553 - Design docs links: - External links: --- ### 🚨 Breaking Changes? - [ ] Yes (explain below) - [ ] No <!-- If yes, describe what needs to be changed downstream: --> --- ### 🔍️ Additional Notes <!-- Anything else reviewers should know (follow-up tasks, known issues, affected areas etc.). --> <!-- ### 📸 Screenshots / Logs --> --------- Co-authored-by: adamdelman <flyn@flyn.cc> Co-authored-by: Tal Haim <tal_haim@external.mckinsey.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR refactors and enhances the database partitioning system for alert activations to improve cross-database compatibility, robustness, and maintainability. The changes establish a cleaner architecture for partition management while adding full PostgreSQL support alongside the existing MySQL implementation.
Key improvements:
partition_keyinteger column computed fromactivation_time, enabling consistent partitioning logic across databasestable_partition_intervaltable persists partition configuration, decoupling interval choice from table structure🛠️ Changes Made
Database Schema:
partition_keycolumn toalert_activationstable (computed fromactivation_time)table_partition_intervalmetadata table to track partition configuration per tablepartition_keyfor MySQLc25e56faecceto handle schema updates and backfill existing dataPartitioning Logic:
PartitionIntervalfrompartition.py→partition_interval.pywith cleaner APIspartititioner.py→partition_bootstrapper.pywith dialect-specific implementationsPartitionBootstrapperMySQL,PartitionBootstrapperPostgres, andPartitionBootstrapperSqliteget_partition_key_value()andget_mysql_partition_key_sql()methods for consistent key generationDatabase Layer:
get_partition_interval_for_table()andset_partition_interval_for_table()to baseDBInterfacecreate_partitions()anddrop_partitions()methodsSQLDB.__new__()to properly route SQLite connectionsnow()function with PostgreSQL-specific compilation for timestamp handlingTesting & CI:
tests/conftest.pyCode Quality:
✅ Checklist
🧪 Testing
Integration Tests:
test_partition_interval_yearweek_matches_mysql_yearweek_mode_1: Make sure the Python YEARWEEK partition key calculation matches MySQL's calaulcationtest_insert_populates_partition_key: Validates automatic partition key computation on inserttest_create_partitions_mysql/postgres: Tests partition creation with different intervals (DAY, MONTH, YEARWEEK)test_drop_partitions_mysql/postgres: Validates retention-based partition cleanupUnit Tests:
test_partitioner.pywith parametrized tests for interval calculationsManual Testing:
CI Updates:
mysqlandpostgresbackends🔗 References
650f0ce2da6f_add_alert_activation.py🚨 Breaking Changes?
Migration Required:
c25e56faeccewhich:partition_keycolumn toalert_activationstable_partition_intervalmetadata tablePARTITION_INTERVALis now validated more strictly and must be one of:DAY,MONTH,YEARWEEK🔍️ Additional Notes
Architecture Decisions:
partition_keyover expression-based partitioning for PostgreSQL compatibility and performancePerformance Considerations:
before_insertlistenerFuture Work:
alert_activations