Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SchemaMigration to an independent object #45908

Merged
merged 1 commit into from Sep 9, 2022

Commits on Sep 8, 2022

  1. Move SchemaMigration to an independent object

    Previously, SchemaMigration inherited from ActiveRecord::Base. This is
    problematic for multiple databases and resulted in building the code in
    AbstractAdapter that was previously there. Rather than hacking around
    the fact that SchemaMigration inherits from Base, this PR makes
    SchemaMigration an independent object. Then each connection can get it's
    own SchemaMigration object. This change required defining the methods
    that SchemaMigration was depending on ActiveRecord::Base for (ex
    create!). I reimplemented only the methods called by the framework as
    this class is no-doc's so it doesn't need to implement anything beyond
    that. Now each connection gets it's own SchemaMigration object which
    stores the connection. I also decided to update the method names (create
    -> create_version, delete_by -> delete_version, delete_all ->
    delete_all_versions) to be more explicit.
    
    This change also required adding a NullSchemaMigraiton class for cases
    when we don't have a connection yet but still need to copy migrations
    from the MigrationContext. Ultimately I think this is a little weird -
    we need to do so much work to pick up a set of files? Maybe something to
    explore in the future.
    
    Aside from removing the hack we added back in #36439 this change will
    enable my work to stop clobbering and depending directly on
    Base.connection in the rake tasks. While working on this I discovered
    that we always have a `ActiveRecord::SchemaMigration` because the
    connection is always on `Base` in the rake tasks. This will free us up
    to do less hacky stuff in the migrations and tasks.
    eileencodes committed Sep 8, 2022
    Configuration menu
    Copy the full SHA
    436277d View commit details
    Browse the repository at this point in the history