Skip to content

Use ActiveRecord::Tasks::DatabaseTasks directly in geo rake tasks

Toon Claes requested to merge tc-geo-use-database-tasks into master

What does this MR do?

Instead of relying on the db: tasks, implement them our self using ActiveRecord::Tasks::DatabaseTasks.

Basically this is mostly copied from activerecord/lib/active_record/railties/databases.rake.

Are there points in the code the reviewer needs to double check?

  • I had to call ActiveRecord::Base.establish_connection(Rails.env.to_sym) to ensure ActiveRecord::Base.connection points to the Geo tracking database. It doesn't look really pretty, but it seems to work. I'm not sure it requires for each task, but just to be sure it's called for each task. Feel free to raise objections if you have some.
  • I'd love to have a method to test if these tasks operate on the tracking database. During development I ran these on a secondary node, so tasks operating on the primary failed because that's read-only. So suggestions to write a test for this are welcome.

Why was this MR needed?

To make the rake geo:db:migrate on a secondary (from Omnibus) work again.

Screenshots

❯ be rake -T | grep geo
rake geo:db:create                                            # Creates the Geo tracking database from config/database_geo.yml for the current RAILS_ENV
rake geo:db:drop                                              # Drops the Geo tracking database from config/database_geo.yml for the current RAILS_ENV
rake geo:db:migrate                                           # Migrate the Geo tracking database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake geo:db:migrate:down                                      # Runs the "down" for a given migration VERSION
rake geo:db:migrate:redo                                      # Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x)
rake geo:db:migrate:status                                    # Display status of migrations
rake geo:db:migrate:up                                        # Runs the "up" for a given migration VERSION
rake geo:db:reset                                             # Drops and recreates the database from db/geo/schema.rb for the current environment and loads the seeds
rake geo:db:rollback                                          # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake geo:db:schema:dump                                       # Create a db/geo/schema.rb file that is portable against any DB supported by AR
rake geo:db:schema:load                                       # Load a schema.rb file into the database
rake geo:db:seed                                              # Load the seed data from db/geo/seeds.rb
rake geo:db:setup                                             # Create the Geo tracking database, load the schema, and initialize with the seed data
rake geo:db:show_encryption_key                               # Display database encryption key
rake geo:db:test:prepare                                      # Check for pending migrations and load the test schema
rake geo:db:version                                           # Retrieves the current schema version number
rake geo:set_primary_node                                     # Make this node the Geo primary

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes gitlab-org/gitlab-ee#3543

Edited by Toon Claes

Merge request reports