Skip to content

Commit

Permalink
Fix/snowflake custom schema (#626)
Browse files Browse the repository at this point in the history
* Fixes already opened transaction issue

For #602

* Fixes #621
  • Loading branch information
drewbanin authored Dec 18, 2017
1 parent 6dbe79b commit 323ab1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 323ab1e

Please sign in to comment.