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

Some changes to hopefully make generating structure.sql easier. #4405

Merged
merged 1 commit into from Aug 4, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Some changes to hopefully make generating structure.sql easier.

When running `bin/rake db:structure:dump`, I get two lines of diff in my
`structure.sql` file:
1. Some trailing space is added to a `CREATE VIEW` declaration.
   - This is pretty harmless, but it is annoying to remove each time.
2. A `DEFINER=` line gets added before our `rails_persons` `VIEW`.
   - This one regularly causes pain, as it breaks `bin/rake db:reset`
     for some reason.

This diff changes things so we remove these changes when dumping the
database schema.
  • Loading branch information...
jfly committed Aug 4, 2019
commit 8163859eb475d051e9ba3796cc2c6292a5c90f55
@@ -3,8 +3,9 @@
# Copied (and modified) from https://stackoverflow.com/a/20695238

def normalize_schema_dump(schema_dump)
schema_dump.gsub(/ AUTO_INCREMENT=\d*/, '')
.rstrip + "\n" # remove extra newlines at the end
schema_dump = schema_dump.gsub(/ AUTO_INCREMENT=\d*/, '').rstrip + "\n" # remove extra newlines at the end
schema_dump = schema_dump.gsub(/ *$/, '') # remove trailing whitespace
schema_dump.gsub(%r{\n.* DEFINER=[^*]* \*/$}, '') # remove DEFINER= declarations
end

Rake::Task["db:structure:dump"].enhance do
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.