Skip to content

Commit

Permalink
Destroy schemas in SingleDB mode only; Set TARGET_DB automatic placeh…
Browse files Browse the repository at this point in the history
…older earlier, but only when --target-db argument was used explicitly
  • Loading branch information
littleK0i committed Apr 11, 2024
1 parent ae10cac commit 2ad3fe9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion snowddl/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions snowddl/app/singledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion snowddl/parser/placeholder.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions snowddl/resolver/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions snowddl/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.25.2"
__version__ = "0.25.3"

0 comments on commit 2ad3fe9

Please sign in to comment.