Skip to content

Conversation

@exterm
Copy link

@exterm exterm commented May 5, 2025

If you pass an ActiveRecord::Relation, it will be executed when the call is analyzed for logging purposes, potentially timing out the migration.

Fix #115

I'm not quite sure why github id displaying my commit as unverified, it should be signed as usual.

If you pass an ActiveRecord::Relation, it will be executed when the call is analyzed for logging purposes, potentially timing out the migration.
@CLAassistant
Copy link

CLAassistant commented May 5, 2025

CLA assistant check
All committers have signed the CLA.

@exterm
Copy link
Author

exterm commented May 5, 2025

Note: I haven't been able to execute the tests locally; there doesn't seem to be documentation on how to do that. I assume I need to configure a database somehow?

# SQL
#
def create_continuous_aggregate(table_name, query, **options)
raise ArgumentError, 'query must be a string' unless query.is_a?(String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about old migrations that are already in place.

Suggested change
raise ArgumentError, 'query must be a string' unless query.is_a?(String)
query = query.to_sql if query.respond_to(:to_sql)
raise ArgumentError, 'query must be a string or implement the `to_sql` method ' unless query.is_a?(String)

Copy link
Author

@exterm exterm May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right to think about backwards compatibility, but if I apply your changes then this PR fixes nothing.

The problem is caused by allowing people to pass an ActiveRecord::Relation as an input to create_continuous_aggregate.

If you want to preserve backwards compatibility for now, we could look into making it a warning instead of an exception.

Copy link
Contributor

@jonatas jonatas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvement @exterm !

Let's avoid breaking compatibility with the previous migrations and allow folks to continue using scopes for it.

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.

Problem: Passing an ActiveRecord::Relation to create_continuous_aggregate in a migration will execute the query

3 participants