aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2017-05-13 23:01:13 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2017-05-15 18:19:12 -0500
commit4b49ab66425283f4b79907873b72236c7ebec0be (patch)
treead0672079425887d6887649fd77167306009c464 /activerecord/lib/active_record
parent486562fa955f2cbd574e7f4099fdf69a49a8ce20 (diff)
downloadrails-4b49ab66425283f4b79907873b72236c7ebec0be.tar.gz
rails-4b49ab66425283f4b79907873b72236c7ebec0be.tar.bz2
rails-4b49ab66425283f4b79907873b72236c7ebec0be.zip
Respect 'ignore_tables' in SQLite structure dump
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/tasks/sqlite_database_tasks.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
index 1f756c2979..5542e5585c 100644
--- a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb
@@ -38,7 +38,16 @@ module ActiveRecord
def structure_dump(filename, extra_flags)
dbfile = configuration["database"]
flags = extra_flags.join(" ") if extra_flags
- `sqlite3 #{flags} #{dbfile} .schema > #{filename}`
+
+ ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
+ if ignore_tables.any?
+ tables = `sqlite3 #{dbfile} .tables`.split - ignore_tables
+ condition = tables.map { |table| "tbl_name = '#{table}'" }.join(" OR ")
+ statement = "SELECT sql FROM sqlite_master WHERE #{condition} ORDER BY tbl_name, type DESC, name"
+ `sqlite3 #{flags} #{dbfile} "#{statement}" > #{filename}`
+ else
+ `sqlite3 #{flags} #{dbfile} .schema > #{filename}`
+ end
end
def structure_load(filename, extra_flags)