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

Fix/snowflake custom schema #626

Merged
merged 2 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion dbt/adapters/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def add_begin_query(cls, profile, name):
def create_schema(cls, profile, schema, model_name=None):
logger.debug('Creating schema "%s".', schema)
sql = cls.get_create_schema_sql(schema)
return cls.add_query(profile, sql, model_name, select_schema=False)
res = cls.add_query(profile, sql, model_name, select_schema=False)

cls.commit_if_has_connection(profile, model_name)

return res

@classmethod
def get_existing_schemas(cls, profile, model_name=None):
Expand Down
7 changes: 7 additions & 0 deletions dbt/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def safe_run_hooks(cls, project, adapter, flat_graph, hook_type):
def create_schemas(cls, project, adapter, flat_graph):
profile = project.run_environment()
required_schemas = cls.get_model_schemas(flat_graph)

# 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(adapter.get_default_schema(profile))

existing_schemas = set(adapter.get_existing_schemas(profile))

for schema in (required_schemas - existing_schemas):
Expand Down