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: dbt clean without profile #2649

Merged
merged 3 commits into from
Jul 27, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


### Fixes
- fast-fail option with adapters that don't support cancelling queries will now passthrough the original error messages ([#2644](https://github.com/fishtown-analytics/dbt/issues/2644))
- fast-fail option with adapters that don't support cancelling queries will now passthrough the original error messages ([#2644](https://github.com/fishtown-analytics/dbt/issues/2644), [#2646](https://github.com/fishtown-analytics/dbt/pull/2646))
- `dbt clean` no longer requires a profile ([#2620](https://github.com/fishtown-analytics/dbt/issues/2620), [#2649](https://github.com/fishtown-analytics/dbt/pull/2649))

Contributors:
- [@joshpeng-quibi](https://github.com/joshpeng-quibi) ([#2646](https://github.com/fishtown-analytics/dbt/pull/2646))
Expand Down
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ jobs:
Set-Service -InputObject $serviceName -StartupType Automatic
Start-Service -InputObject $serviceName

createdb.exe -U postgres dbt
psql.exe -U postgres -c "CREATE ROLE root WITH PASSWORD 'password';"
psql.exe -U postgres -c "ALTER ROLE root WITH LOGIN;"
psql.exe -U postgres -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root WITH GRANT OPTION;"
psql.exe -U postgres -c "CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER;"
psql.exe -U postgres -c "ALTER ROLE noaccess WITH LOGIN;"
psql.exe -U postgres -c "GRANT CONNECT ON DATABASE dbt TO noaccess;"
& $env:PGBIN\createdb.exe -U postgres dbt
& $env:PGBIN\psql.exe -U postgres -c "CREATE ROLE root WITH PASSWORD 'password';"
& $env:PGBIN\psql.exe -U postgres -c "ALTER ROLE root WITH LOGIN;"
& $env:PGBIN\psql.exe -U postgres -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root WITH GRANT OPTION;"
& $env:PGBIN\psql.exe -U postgres -c "CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER;"
& $env:PGBIN\psql.exe -U postgres -c "ALTER ROLE noaccess WITH LOGIN;"
& $env:PGBIN\psql.exe -U postgres -c "GRANT CONNECT ON DATABASE dbt TO noaccess;"
displayName: Install postgresql and set up database

- task: UsePythonVersion@0
Expand Down
6 changes: 4 additions & 2 deletions core/dbt/task/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import os
import shutil

from dbt.task.base import ConfiguredTask
from dbt.task.base import BaseTask
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.config import UnsetProfileConfig


class CleanTask(ConfiguredTask):
class CleanTask(BaseTask):
ConfigType = UnsetProfileConfig

def __is_project_path(self, path):
proj_path = os.path.abspath('.')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil
import tempfile
from test.integration.base import DBTIntegrationTest, use_profile
from dbt.exceptions import CompilationException
Expand Down Expand Up @@ -34,6 +33,9 @@ def packages_config(self):
def run_deps(self):
return self.run_dbt(["deps"])

def run_clean(self):
return self.run_dbt(['clean'])

@use_profile('postgres')
def test_postgres_simple_dependency(self):
self.run_deps()
Expand All @@ -56,6 +58,10 @@ def test_postgres_simple_dependency(self):
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")

assert os.path.exists('target')
self.run_clean()
assert not os.path.exists('target')

@use_profile('postgres')
def test_postgres_simple_dependency_with_models(self):
self.run_deps()
Expand All @@ -73,6 +79,10 @@ def test_postgres_simple_dependency_with_models(self):
self.assertEqual(created_models['view_model'], 'view')
self.assertEqual(created_models['view_summary'], 'view')

assert os.path.exists('target')
self.run_clean()
assert not os.path.exists('target')


class TestSimpleDependencyUnpinned(DBTIntegrationTest):
def setUp(self):
Expand Down Expand Up @@ -234,9 +244,11 @@ def test_postgres_empty_models_not_compiled_in_dependencies(self):

class TestSimpleDependencyNoProfile(TestSimpleDependency):
def run_deps(self):
tmpdir = tempfile.mkdtemp()
try:
with tempfile.TemporaryDirectory() as tmpdir:
result = self.run_dbt(["deps", "--profiles-dir", tmpdir])
finally:
shutil.rmtree(tmpdir)
return result

def run_clean(self):
with tempfile.TemporaryDirectory() as tmpdir:
result = self.run_dbt(["clean", "--profiles-dir", tmpdir])
return result