Forked from kevinhq/add_virtual_column_index_to_ahoy_events.rb
Created
November 25, 2020 02:20
-
-
Save 123ish/c9fda2da4be3f1f7e5a73ccc67fee4e7 to your computer and use it in GitHub Desktop.
Virtual Column Index for ahoy_events table
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
class AddVirtualColumnIndexToAhoyEvents < ActiveRecord::Migration[6.0] | |
def up | |
ActiveRecord::Base.connection.execute ( | |
'ALTER TABLE ahoy_events ADD properties_id INT AS (JSON_UNQUOTE(properties->"$.id")) STORED;' | |
) | |
ActiveRecord::Base.connection.execute ( | |
'ALTER TABLE ahoy_events ADD INDEX (properties_id);' | |
) | |
end | |
def down | |
ActiveRecord::Base.connection.execute ( | |
"ALTER TABLE ahoy_events DROP properties_id;" | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment