title: DBT custom schema using folder structure
body: <p>is there a way in DBT to create custom schemas for a model in a derived way by looking at the folder structure?</p>
  <p>For example, say this is my structure:</p>
  <pre><code>models
  └-- product1
      └-- team1
      |   └-- model1.sql
      └-- team2
          └-- model2.sql
  </code></pre>
  <p>In this case, model1.sql would be created in the schema <code>product1_team1</code> whereas model2.sql would be created in the schema <code>product1_team2</code>. I guess I can specify those &quot;by hand&quot; in the <code>dbt_project.yml</code> file, but I was wondering if there was a way to do this in an automated way - so that every new model or folder is automatically created in the right schema.</p>
  <p>I was looking at custom schema macros (<a href="https://docs.getdbt.com/docs/building-a-dbt-project/building-models/using-custom-schemas" rel="noreferrer">https://docs.getdbt.com/docs/building-a-dbt-project/building-models/using-custom-schemas</a>) but it seems to be plain jinja or simple Python built-ins. Not sure how I would be able to access folder paths in those macros.</p>
  <p>Also, is there a way to write a macro in Python? as it could be relatively straightforward knowing the file path and with the os module.</p>