Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do case-insensitive schema comparisons to test for schema existance #1663

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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