fix finding tables for spec truncation

refs CNVS-23621

Change-Id: I19218b4453d772f20e22767564622e131387e918
Reviewed-on: https://gerrit.instructure.com/65662
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2015-10-22 13:05:25 -06:00
parent 95569f5ef3
commit 4070cbde22
1 changed files with 5 additions and 3 deletions

View File

@ -252,12 +252,14 @@ def truncate_all_tables
model_connections.each do |connection|
if connection.adapter_name == "PostgreSQL"
# use custom SQL to exclude tables from extensions
schema = connection.shard.name if connection.instance_variable_get(:@config)[:use_qualified_names]
table_names = connection.query(<<-SQL, 'SCHEMA').map(&:first)
SELECT tablename
FROM pg_tables
WHERE schemaname = ANY (current_schemas(false)) AND NOT tablename IN (
SELECT CAST(objid::regclass AS VARCHAR) FROM pg_depend WHERE deptype='e'
)
WHERE schemaname = #{schema ? "'#{schema}'" : 'ANY (current_schemas(false))'}
AND NOT tablename IN (
SELECT CAST(objid::regclass AS VARCHAR) FROM pg_depend WHERE deptype='e'
)
SQL
table_names.delete('schema_migrations')
connection.execute("TRUNCATE TABLE #{table_names.map { |t| connection.quote_table_name(t) }.join(',')}")