Skip to content

Conversation

@voarsh2
Copy link

@voarsh2 voarsh2 commented Aug 4, 2025

Building upon #56

@jamessewell
Can you get a chance to review this? Would be a shame to have wasted my time and effort on this for something that was asked on this repo for a while.
This is model declaration of the policies, building on top of the programmatic API's for retention policy and compression

voarsh and others added 3 commits April 25, 2025 20:32
This commit adds support for TimescaleDB's retention policy and compression features:

- Add RetentionPolicy class with methods to add and remove retention policies
- Add CompressionPolicy class with methods to enable compression, add/remove policies, and get stats
- Extend TimescaleManager with methods for managing retention and compression
- Add comprehensive tests using TransactionTestCase for self-contained testing
- Update README with examples of how to use the new APIs, including in migrations

These APIs provide a programmatic way to manage TimescaleDB's data lifecycle features.
The implementation uses a method-based approach where you call methods on the
`timescale` manager, rather than a declarative approach in model definitions.

Part of Milestone 2 roadmap. roadmap. Ref: jamessewell#23
This commit introduces a comprehensive set of migration operations for managing TimescaleDB retention and compression policies in Django. Key additions include:

- New `TimescaleConfig` class for app configuration.
- Migration operations for adding and removing retention and compression policies.
- A module for TimescaleDB migration operations, including examples and usage documentation.
- Unit tests to ensure the functionality of the migration operations.

These changes enhance the integration of TimescaleDB with Django's migration framework, allowing for declarative management of data lifecycle features.
Implement production-ready TimescaleDB policy management system with both
declarative and programmatic APIs, featuring complete test coverage and
robust error handling.

Core improvements:
- Fix retention policy removal to return correct boolean values
- Enhance compression policy handling consistency
- Resolve Django migration state handling issues
- Improve error handling for edge cases

Testing infrastructure:
- Add comprehensive test suite (77 tests, 100% pass rate)
- Implement self-contained test architecture
- Fix Django configuration in all test files
- Add individual migration operation testing
- Cover real-world scenarios and edge cases

Features:
- Declarative policy definition via model TimescalePolicies class
- Programmatic API with 5 individual migration operations
- Automatic migration generation and policy updates
- Data-safe policy changes with existing data preservation
- Backward compatibility with existing implementations

This makes the TimescaleDB Django integration production-ready with
maximum flexibility for different use cases while maintaining full
compatibility and data safety.
@areski
Copy link

areski commented Sep 10, 2025

This looks great, thanks for sharing!

@jamessewell, we would love your inputs

@boosh
Copy link

boosh commented Nov 10, 2025

Would be great to get this reviewed please @jamessewell

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.

4 participants