Skip to content

Commit

Permalink
Merge pull request #1663 from edmundyan/ey_create_schemas_lowered
Browse files Browse the repository at this point in the history
Do case-insensitive schema comparisons to test for schema existance
  • Loading branch information
drewbanin authored Aug 6, 2019
2 parents 7901413 + e867cfa commit 3e3c69e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,23 +305,16 @@ 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 = 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(
Expand Down

0 comments on commit 3e3c69e

Please sign in to comment.