Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-cgorrie committed Dec 12, 2023
1 parent 16801b3 commit b11882c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/snowcli/cli/appify/generate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Generator, List
from typing import Generator, List, Tuple
from contextlib import contextmanager
from pathlib import Path
from strictyaml import YAML, load

from snowcli.cli.project.util import to_identifier
from snowcli.cli.project.schemas.project_definition import project_schema

APP_PUBLIC = "app_public"


@contextmanager
def modify_yml(path: Path) -> Generator[YAML, None, None]:
Expand All @@ -21,6 +23,14 @@ def modify_yml(path: Path) -> Generator[YAML, None, None]:
f.write(yml.as_yaml())


def get_ordering(reference_json: Path) -> List[Tuple[str, str]]:
"""
Return a list of (schema, object name) tuples that represent a
depth-first search of the DAG that represents their dependencies.
"""
return []


def generate_setup_statements(
stages_path: Path,
metadata_path: Path,
Expand All @@ -29,8 +39,9 @@ def generate_setup_statements(
"""
Generator that yields all the statements necessary to build the setup script.
"""
yield "create application role if not exists app_public;"
yield f"create application role if not exists {APP_PUBLIC}"

schemas = [f.name for f in sorted(metadata_path.iterdir()) if f.is_dir()]
for schema in schemas:
yield f"create or alter versioned schema {to_identifier(schema)};"
yield f"create or alter versioned schema {to_identifier(schema)}"
yield f"grant usage on schema {to_identifier(schema)} to application role {APP_PUBLIC}"
18 changes: 10 additions & 8 deletions src/snowcli/cli/appify/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MetadataDumper(SqlExecutionMixin):
def __init__(self, database: str, project_path: Path):
super().__init__()
self.stage_manager = StageManager()
self.database = database
# FIXME: deal with quoted identifiers
self.database = database.upper()
self.project_path = project_path
self.schemas = []
self.referenced_stage_ids = []
Expand Down Expand Up @@ -192,8 +193,8 @@ def process_schema(self, schema: str) -> None:
with open(schema_path / filename, "w") as f:
f.write(ddl)
self.update_references(schema_path, literal, domain)
#dump references

# dump references
with open(schema_path / REFERENCES_FILE_NAME, "w") as ref_file:
json.dump(self.references, ref_file)

Expand All @@ -205,11 +206,12 @@ def dump_stage(self, stage_id: str) -> None:
stage_folder.mkdir(parents=True)
self.stage_manager.get(stage_id, stage_folder)

def update_references(self, schema_path: str, object_name: str, domain: str) -> None:
def update_references(
self, schema_path: str, object_name: str, domain: str
) -> None:
log.info(f"grabbing references for object {object_name} with domain {domain}")
references_cursor = self._execute_query(
f"select system$GET_REFERENCES_BY_NAME_AS_OF_TIME({object_name}, '{domain}')"
)
f"select system$GET_REFERENCES_BY_NAME_AS_OF_TIME({object_name}, '{domain}')"
)
references_list = json.loads(references_cursor.fetchone()[0])
self.references[object_name] = references_list;

self.references[object_name] = references_list

0 comments on commit b11882c

Please sign in to comment.