/**
 * Copyright 2010-2014 Axel Fontaine
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.flywaydb.core.internal.dbsupport.redshift;

import java.sql.SQLException;
import java.util.List;

import org.flywaydb.core.internal.dbsupport.DbSupport;
import org.flywaydb.core.internal.dbsupport.JdbcTemplate;
import org.flywaydb.core.internal.dbsupport.Table;
import org.flywaydb.core.internal.dbsupport.postgresql.PostgreSQLSchema;

/**
 * Redshift implementation of Schema.
 */
public class RedshiftSchema extends PostgreSQLSchema {
    /**
     * Creates a new Redshift schema.
     *
     * @param jdbcTemplate The Jdbc Template for communicating with the DB.
     * @param dbSupport    The database-specific support.
     * @param name         The name of the schema.
     */
    public RedshiftSchema(JdbcTemplate jdbcTemplate, DbSupport dbSupport, String name) {
        super(jdbcTemplate, dbSupport, name);
    }

    @Override
    protected void doClean() throws SQLException {
        for (Table table : allTables()) {
            table.drop();
        }
        
        // Custom sequences, functions, domains and types are not supported by Redshift.
    }    
    
    @Override
    protected Table[] doAllTables() throws SQLException {
        List<String> tableNames =
                jdbcTemplate.queryForStringList(
                        //Search for all the table names
                        "SELECT t.table_name FROM information_schema.tables t" +
                                //in this schema
                                " WHERE table_schema=?" +
                                //that are real tables (as opposed to views)
                                " AND table_type='BASE TABLE'",
                                //No need for further predicates, since Redshift does not support inheritance
                        name);
        //Views and child tables are excluded as they are dropped with the parent table when using cascade.

        Table[] tables = new Table[tableNames.size()];
        for (int i = 0; i < tableNames.size(); i++) {
            tables[i] = new RedshiftTable(jdbcTemplate, dbSupport, this, tableNames.get(i));
        }
        return tables;
    }    
    
    @Override
    public Table getTable(String tableName) {
        return new RedshiftTable(jdbcTemplate, dbSupport, this, tableName);
    }    

}

@@ -714,63 +714,8 @@
 t;%0A%0A
-import org.flywaydb.core.internal.dbsupport.DbSupport;%0A
 impo
@@ -819,16 +819,92 @@
 .Table;%0A
+import org.flywaydb.core.internal.dbsupport.postgresql.PostgreSQLDbSupport;%0A
 import o
@@ -1369,16 +1369,26 @@
 mplate, 
+PostgreSQL
 DbSuppor

Fix to RedshiftSchema to support an upstream change that involves type parameterization. The super class Schema ...changed to... Schema<S extends DbSupport>