googleapis / ruby-spanner-activerecord

Spanner<->ActiveRecord adapter for Ruby
MIT License
87 stars 30 forks source link

Is there a way to make the DDL run asynchronously? #265

Closed ruzia closed 11 months ago

ruzia commented 11 months ago

Adding an index to a table with 100 million data items is very time consuming (like a day or more). The gcloud command has "--async", but is there any way to do the same thing with db:migrate in rails?

olavloite commented 11 months ago

Not directly, but you can run migrations programmatically. You could then put that in an async block to achive the same. See this test case for an example for how you can run a migration programmatically: https://github.com/googleapis/ruby-spanner-activerecord/blob/5060fb51b29aefd3c015ec729eae03454ecfa8a7/test/migrations_with_mock_server/migrations_with_mock_server_test.rb#L66

ruzia commented 11 months ago

@olavloite Thanks for reply! I see, but I would like to switch between async or not as needed in db:migrate if possible.

From looking at the code below, I thought it might work if, for example, I could pass wait_until_done as an argument to ddl_batch and then pass it to run_batch as well. What do you think?

https://github.com/googleapis/ruby-spanner-activerecord/blob/ea626e8a8086484a73b5c2f0229e7492c54ea948/lib/activerecord_spanner_adapter/connection.rb#L134