diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ef079..bdde20c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [0.25.3] - 2024-04-11 + +- Add explicit setting to destroy schemas. Use it in SingleDB mode only. Do not attempt to destroy schemas in normal mode. +- Set `TARGET_DB` automatic placeholder earlier, but only if `--target-db` argument was specified. + ## [0.25.2] - 2024-04-03 - Added CLI options `--refresh-stage-encryption` and `--refresh-secrets` to SingleDB mode. diff --git a/snowddl/app/base.py b/snowddl/app/base.py index 1030a3a..169d2fe 100644 --- a/snowddl/app/base.py +++ b/snowddl/app/base.py @@ -284,7 +284,7 @@ def init_config(self): placeholder_values = self.get_placeholder_values() parser = PlaceholderParser(config, self.config_path) - parser.load_placeholders(placeholder_path, placeholder_values) + parser.load_placeholders(placeholder_path, placeholder_values, self.args) if config.errors: self.output_config_errors(config) diff --git a/snowddl/app/singledb.py b/snowddl/app/singledb.py index 0e87541..b21c25b 100644 --- a/snowddl/app/singledb.py +++ b/snowddl/app/singledb.py @@ -219,9 +219,6 @@ def init_config(self): else: self.target_db = self.config_db - # Add placeholder for TARGET_DB - config.add_placeholder("TARGET_DB", str(self.target_db)) - return self.convert_config(config) def convert_config(self, original_config: SnowDDLConfig): @@ -262,6 +259,7 @@ def init_settings(self): settings = super().init_settings() settings.include_databases = [self.target_db] settings.ignore_ownership = True + settings.destroy_schemas = True return settings diff --git a/snowddl/parser/placeholder.py b/snowddl/parser/placeholder.py index b8122d1..dece67c 100644 --- a/snowddl/parser/placeholder.py +++ b/snowddl/parser/placeholder.py @@ -1,6 +1,7 @@ from pathlib import Path from typing import Dict, Optional +from snowddl.blueprint import DatabaseIdent from snowddl.parser.abc_parser import AbstractParser @@ -19,12 +20,17 @@ def load_blueprints(self): # This is a special parser that does not load any blueprints, but it loads placeholders instead pass - def load_placeholders(self, placeholder_path: Optional[Path] = None, placeholder_values: Optional[Dict] = None): + def load_placeholders( + self, placeholder_path: Optional[Path] = None, placeholder_values: Optional[Dict] = None, args: Optional[Dict] = None + ): # 1) Start with standard placeholders, always available placeholders = { "ENV_PREFIX": self.env_prefix, } + if args and args.get("target_db"): + placeholders["TARGET_DB"] = str(DatabaseIdent(self.env_prefix, args.get("target_db"))) + # 2) Merge with placeholders from normal config file placeholders.update( self.normalise_params_dict(self.parse_single_file(self.base_path / "placeholder.yaml", placeholder_json_schema)) diff --git a/snowddl/resolver/schema.py b/snowddl/resolver/schema.py index df393a5..4a77392 100644 --- a/snowddl/resolver/schema.py +++ b/snowddl/resolver/schema.py @@ -77,6 +77,12 @@ def drop_object(self, row: dict): return ResolveResult.DROP + def destroy(self): + # Schemas are normally dropped automatically on DROP DATABASE + # But in some cases explicit DROP SCHEMA might be required, e.g. for SingleDB mode + if self.engine.settings.destroy_schemas: + super().destroy() + def _post_process(self): for result in self.resolved_objects.values(): if result != ResolveResult.NOCHANGE: diff --git a/snowddl/settings.py b/snowddl/settings.py index dbe5ef7..38843a3 100644 --- a/snowddl/settings.py +++ b/snowddl/settings.py @@ -25,6 +25,7 @@ class SnowDDLSettings(BaseModelWithConfig): include_object_types: List[ObjectType] = [] include_databases: List[DatabaseIdent] = [] ignore_ownership: bool = False + destroy_schemas: bool = False max_workers: int = 8 # Options specific for snowddl-convert diff --git a/snowddl/version.py b/snowddl/version.py index 97b0e62..81fc784 100644 --- a/snowddl/version.py +++ b/snowddl/version.py @@ -1 +1 @@ -__version__ = "0.25.2" +__version__ = "0.25.3"