Last active
January 23, 2021 06:15
-
-
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
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
# 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