forked from snowflakedb/snowflake-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9aeda6
commit a0a248f
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
import typer | ||
from snowcli.cli.common.decorators import ( | ||
global_options, | ||
global_options_with_connection, | ||
) | ||
from snowcli.cli.common.flags import DEFAULT_CONTEXT_SETTINGS | ||
from snowcli.cli.nativeapp.init import nativeapp_init | ||
from snowcli.output.decorators import with_output | ||
from snowcli.output.types import CommandResult, MessageResult | ||
|
||
from snowcli.cli.appify.metadata import MetadataDumper | ||
|
||
# from snowcli.cli.appify.generate import ... | ||
|
||
app = typer.Typer( | ||
context_settings=DEFAULT_CONTEXT_SETTINGS, | ||
name="appify", | ||
help="Generate a Native Application project from an existing database", | ||
) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@app.command() | ||
@with_output | ||
@global_options_with_connection | ||
def appify( | ||
db: str = typer.Argument( | ||
..., | ||
help="The database to extract metadata from and turn into an app.", | ||
), | ||
name: str = typer.Option( | ||
None, | ||
help=f"""The name of the native application project to include in snowflake.yml. When not specified, it is | ||
generated from the name of the database. Names are assumed to be unquoted identifiers whenever possible, but | ||
can be forced to be quoted by including the surrounding quote characters in the provided value.""", | ||
), | ||
**options, | ||
) -> CommandResult: | ||
""" | ||
Initializes a Native Apps project from a database. | ||
""" | ||
return MessageResult(f"Creating from {db}.") | ||
|
||
# project = nativeapp_init(path=db, name=name) | ||
# metadata_path = project.path / "metadata" | ||
# dumper = MetadataDumper(db, metadata_path) | ||
|
||
# for stage in dumper.stages: | ||
# pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from functools import cached_property | ||
from pathlib import Path | ||
from typing import Callable, List, Literal, Optional | ||
|
||
from click.exceptions import ClickException | ||
from snowcli.cli.common.sql_execution import SqlExecutionMixin | ||
from snowcli.cli.object.stage.manager import StageManager | ||
from snowcli.cli.project.definition_manager import DefinitionManager | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
REFERENCES_BY_NAME_JSON = "references_by_name.json" | ||
REFERENCES_OBJECT_TYPES = ["function", "table", "view"] | ||
|
||
|
||
class MetadataDumper(SqlExecutionMixin): | ||
""" | ||
Dumps a Snowflake database as folders and files in a local filesystem. | ||
Schemas become directories, and other objects become sql files with their DDL. | ||
Dependencies between objects that use the reference framework are stored in a JSON file. | ||
Stages are dumped in entirety and become directories. | ||
""" | ||
|
||
database: str | ||
target_path: DefinitionManager | ||
|
||
def __init__(self, database: str, target_path: Path): | ||
super().__init__() | ||
self.database = database | ||
self.target_path = target_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from snowcli.api.plugin.command import ( | ||
SNOWCLI_ROOT_COMMAND_PATH, | ||
CommandSpec, | ||
CommandType, | ||
plugin_hook_impl, | ||
) | ||
from snowcli.cli.appify import commands | ||
|
||
|
||
@plugin_hook_impl | ||
def command_spec(): | ||
return CommandSpec( | ||
parent_command_path=SNOWCLI_ROOT_COMMAND_PATH, | ||
command_type=CommandType.SINGLE_COMMAND, | ||
typer_instance=commands.app, | ||
) |