From 265f6d3ce5d4a77d6ce44a5bcb592944172d2e2c Mon Sep 17 00:00:00 2001 From: Edmund Yan Date: Mon, 5 Aug 2019 14:12:36 -0400 Subject: [PATCH 1/2] Do case-insensitive schema comparison before trying to create a schema --- core/dbt/task/runnable.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/dbt/task/runnable.py b/core/dbt/task/runnable.py index 0b107d1819f..aa43b53b93d 100644 --- a/core/dbt/task/runnable.py +++ b/core/dbt/task/runnable.py @@ -316,12 +316,14 @@ def create_schemas(self, adapter, selected_uids): required_databases = set(db for db, _ in required_schemas) - existing_schemas = set() + existing_schemas_lowered = set() for db in required_databases: - existing_schemas.update((db, s) for s in adapter.list_schemas(db)) + existing_schemas_lowered.update( + (db.lower(), s.lower()) for s in adapter.list_schemas(db)) - for database, schema in (required_schemas - existing_schemas): - adapter.create_schema(database, schema) + for db, schema in required_schemas: + if (db.lower(), schema.lower()) not in existing_schemas_lowered: + adapter.create_schema(db, schema) def get_result(self, results, elapsed_time, generated_at): return ExecutionResult( From e867cfa4a23df8f89892217f5e3ac02792423369 Mon Sep 17 00:00:00 2001 From: Edmund Yan Date: Mon, 5 Aug 2019 23:28:48 -0400 Subject: [PATCH 2/2] Remove profile schema as we no longer run 'use schema' --- core/dbt/task/runnable.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/dbt/task/runnable.py b/core/dbt/task/runnable.py index aa43b53b93d..c7443d44fb8 100644 --- a/core/dbt/task/runnable.py +++ b/core/dbt/task/runnable.py @@ -305,15 +305,6 @@ def get_model_schemas(self, selected_uids): def create_schemas(self, adapter, selected_uids): required_schemas = self.get_model_schemas(selected_uids) - - # Snowflake needs to issue a "use {schema}" query, where schema - # is the one defined in the profile. Create this schema if it - # does not exist, otherwise subsequent queries will fail. Generally, - # dbt expects that this schema will exist anyway. - required_schemas.add( - (self.config.credentials.database, self.config.credentials.schema) - ) - required_databases = set(db for db, _ in required_schemas) existing_schemas_lowered = set()