Created
October 5, 2021 17:58
-
-
Save emptyflask/4a5da8948a87c916fe8ec52d2aa59bd9 to your computer and use it in GitHub Desktop.
DB view migration wrapper using Scenic
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
require 'migration/rebuild' | |
class ConvertFilmIdsToStrings < ActiveRecord::Migration[5.1] | |
include Migration::Rebuild | |
EVENT_VIEWS = { | |
# view: version | |
eventbase_events: 26, | |
eventbase_entities: 34, | |
admin_entity_stats: 8, | |
facebook_events: 5 | |
} | |
def up | |
rebuild(EVENT_VIEWS) do | |
remove_foreign_key :screenings, :films | |
change_column :films, :id, :string | |
change_column :screenings, :film_id, :string | |
add_foreign_key :screenings, :films | |
end | |
end | |
def down | |
rebuild(EVENT_VIEWS) do | |
remove_foreign_key :screenings, :films | |
change_column :films, :id, :integer, using: 'id::integer' | |
change_column :screenings, :film_id, :integer, using: 'id::integer' | |
add_foreign_key :screenings, :films | |
end | |
end | |
end |
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
module Migration | |
module Rebuild | |
def rebuild(views=[]) | |
views.each {|view, version| drop_view view} | |
yield | |
views.each {|view, version| create_view view, version: version} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment