Skip to content

Instantly share code, notes, and snippets.

@mlt
Last active January 23, 2021 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlt/34cef6189124c3f845309852beb3a832 to your computer and use it in GitHub Desktop.
Save mlt/34cef6189124c3f845309852beb3a832 to your computer and use it in GitHub Desktop.
Mixin for ActiveRecord/Rails to dump Sqitch metadata along with DB schema/structure
# Chain sqitch metadata dump to structure.sql dumping
#
# Structure dump does not include any data
# whilst Sqitch expect its metadata at all times.
# This allows to cache DB schema in a single sql dump to speed up tests
# while allowing continuous deployment of new changes with sqitch.
#
# sqitch deploy ...
# bundle exec rails db:structure:dump RAILS_ENV=test
# bundle exec rails test
module SqitchDumper
def structure_dump(filename, extra_flags)
super
cmd = "pg_dump -a -n sqitch -x -O #{configuration['database']}"
File.open(filename, 'a') { |f| f << `#{cmd}` } end
end
ActiveRecord::Tasks::PostgreSQLDatabaseTasks.prepend(SqitchDumper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment