Skip to content

Commit

Permalink
ordering dump
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ssuresh committed Dec 12, 2023
1 parent 9fc4731 commit 81b0346
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/snowcli/cli/appify/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
log = logging.getLogger(__name__)

CATALOG_FILE_NAME = "catalog.json"
ORDERING_FILE_NAME = "ordering.json"

DOMAIN_TO_SHOW_COMMAND_NOUN = {
"function": "user functions",
Expand Down Expand Up @@ -105,6 +106,10 @@ def stages_path(self) -> Path:
def catalog_path(self) -> Path:
return self.metadata_path / CATALOG_FILE_NAME

@cached_property
def ordering_path(self) -> Path:
return self.metadata_path / ORDERING_FILE_NAME

def get_stage_path(self, stage_id: str) -> Path:
(db, schema, stage_name) = split_fqn_id(stage_id)
return self.stages_path / db / schema / stage_name
Expand Down Expand Up @@ -163,6 +168,7 @@ def execute(self) -> None:

self.dump_references()
ordered_objects = self.get_ordering()
self.dump_object_ordering(ordered_objects)

def process_schema(self, schema: str) -> None:
"""
Expand Down Expand Up @@ -201,7 +207,7 @@ def process_schema(self, schema: str) -> None:
f"select get_ddl('{domain}', {literal})"
)
ddl = ddl_cursor.fetchone()[0]
filename = f"{object['name']}.sql"
filename = f"{object_name}.sql"
with open(schema_path / filename, "w") as f:
f.write(ddl)
self.update_references(schema_path, schema, object_name, domain)
Expand All @@ -211,6 +217,11 @@ def dump_references(self):
with open(self.catalog_path, "w") as ref_file:
json.dump(self.references, ref_file)

def dump_object_ordering(self, ordering: List[str]):
# dump references
with open(self.ordering_path, "w") as ref_file:
json.dump(ordering, ref_file)

def dump_stage(self, stage_id: str) -> None:
"""
Downloads the entire contents of a stage, recursively.
Expand Down

0 comments on commit 81b0346

Please sign in to comment.