-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for apps in subdirectories #18
Open
sfc-gh-pjafari
wants to merge
2
commits into
main
Choose a base branch
from
pj-apps-in-subdirs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
snowflake.local.yml | ||
output/** |
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,59 @@ | ||
# Apps in subdirectories | ||
|
||
This Snowflake Native Application sample demonstrates how to utilize subdirectories to hold multiple versions of your Native Application in the same stage. This feature is only available in SnowCLI versions 3.x.x or later. | ||
|
||
## Getting Started | ||
|
||
### Examine the folders structure | ||
|
||
In this example, the application source files are organized into two folders under the root directory. Each folder contains all the source files required to create and run a Native Application. | ||
|
||
FIX THIS: | ||
|
||
``` | ||
. | ||
├── README.md | ||
├── snowflake.yml | ||
├── v1 | ||
│ ├── README.md | ||
│ ├── manifest.yml | ||
│ └── setup_script.sql | ||
└── v2 | ||
├── README.md | ||
├── manifest.yml | ||
└── setup_script.sql | ||
``` | ||
|
||
### Project Definition File | ||
|
||
To include multiple Native Apps in the same stage, we have to specify subdirectories for the stage that host each applications' source files. Application Package Entity definition includes a `stage_subdirectory` field for this purpose. You can set this field to the subdirectory in the stage that you wish to create an Application object or a Version from. | ||
|
||
In this example, we have created two Application Package entities in the definition file, both of which refer to the **same** Application Package in Snowflake (same value for the `identifier` field). Each of this Package entities have a distinct `stage_subdirectory` which tells the CLI to create and manage the application source files within that subdirectory in the stage. | ||
|
||
For this example, we will demonstrate creating and versioning apps from distinct subdirectories in the Stage of one Application Package in snowflake using the CLI. To achieve this, we have defined two Application entities in the project definition file, each `from` one of the Application Package entities as the `target`. Notice that the `identifier` fields of the Applications are different, as to not override one another. | ||
|
||
## Create a Native Application | ||
|
||
Execute the following command: | ||
|
||
```bash | ||
snow app run --app-entity-id=app_v1 | ||
``` | ||
Note that we specified the Application Entity we want to run. Application Entity `app_v1` is created from Package Entity `pkg_v1` as instructed in project definition file. All the artifacts listed in `pkg_v1` are deployed to the stage under the `stage_subdirectory`: `v1`. | ||
|
||
|
||
Now let's do the same for the other app: | ||
|
||
```bash | ||
snow app run --app-entity-id=app_v2 | ||
``` | ||
The above command will create `app_v2` from Application Entity `pkg_v2`. All the artifacts listed in `pkg_v2` have been deployed to the stage under the `stage_subdirectory`: `v2`. | ||
|
||
## Create a Version | ||
|
||
Execute the following command: | ||
```bash | ||
snow app version create version1 --app-entity-id=app_v1 | ||
``` | ||
Above command will create a version from the artifacts for the selected Application Entity which are under `stage_subdirectory`: `v1` in the stage. | ||
|
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,36 @@ | ||
# This is a project definition file, a required component if you intend to use Snowflake CLI in a project directory such as this template. | ||
|
||
definition_version: 2 | ||
entities: | ||
pkg_v1: | ||
type: application package | ||
identifier: <% fn.concat_ids('apps_in_subdir_pkg', ctx.env.suffix) %> | ||
artifacts: | ||
- src: v1/* | ||
dest: ./ | ||
stage_subdirectory: v1 | ||
|
||
|
||
pkg_v2: | ||
type: application package | ||
identifier: <% fn.concat_ids('apps_in_subdir_pkg', ctx.env.suffix) %> | ||
artifacts: | ||
- src: v2/* | ||
dest: ./ | ||
stage_subdirectory: v2 | ||
|
||
app_v1: | ||
type: application | ||
from: | ||
target: pkg_v1 | ||
identifier: <% fn.concat_ids('apps_in_subdir_v1', ctx.env.suffix) %> | ||
|
||
app_v2: | ||
type: application | ||
from: | ||
target: pkg_v2 | ||
identifier: <% fn.concat_ids('apps_in_subdir_v2', ctx.env.suffix) %> | ||
|
||
env: | ||
suffix: <% fn.concat_ids('_', fn.sanitize_id(fn.get_username('unknown_user')) | lower) %> | ||
|
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,20 @@ | ||
## Welcome to your First Snowflake Native App! | ||
|
||
In this Snowflake Native App, you will be able to explore some basic concepts such as application role, versioned schemas and creating procedures and functions within a setup script. | ||
|
||
For more information about a Snowflake Native App, please read the [official Snowflake documentation](https://docs.snowflake.com/en/developer-guide/native-apps/native-apps-about) which goes in depth about many additional functionalities of this framework. | ||
|
||
## Using the application after installation | ||
To interact with the application after it has successfully installed in your account, switch to the application owner role first. | ||
|
||
### Calling a stored procedure | ||
|
||
``` | ||
CALL <your_application_name>.<schema_name>.<stored_procedure_name_with_args>; | ||
``` | ||
|
||
### Calling a function | ||
|
||
``` | ||
SELECT <your_application_name>.<schema_name>.<udf_with_args>; | ||
``` |
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,8 @@ | ||
# This is a manifest.yml file, a required component of creating a Snowflake Native App. | ||
# This file defines properties required by the application package, including the location of the setup script and version definitions. | ||
# Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-manifest for a detailed understanding of this file. | ||
|
||
manifest_version: 1 | ||
artifacts: | ||
setup_script: setup_script.sql | ||
readme: README.md |
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,11 @@ | ||
-- This is the setup script that runs while installing a Snowflake Native App in a consumer account. | ||
-- To write this script, you can familiarize yourself with some of the following concepts: | ||
-- Application Roles | ||
-- Versioned Schemas | ||
-- UDFs/Procs | ||
-- Extension Code | ||
-- Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-setup-script for a detailed understanding of this file. | ||
|
||
CREATE OR ALTER VERSIONED SCHEMA core; | ||
|
||
-- The rest of this script is left blank for purposes of your learning and exploration. |
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,20 @@ | ||
## Welcome to your First Snowflake Native App! | ||
|
||
In this Snowflake Native App, you will be able to explore some basic concepts such as application role, versioned schemas and creating procedures and functions within a setup script. | ||
|
||
For more information about a Snowflake Native App, please read the [official Snowflake documentation](https://docs.snowflake.com/en/developer-guide/native-apps/native-apps-about) which goes in depth about many additional functionalities of this framework. | ||
|
||
## Using the application after installation | ||
To interact with the application after it has successfully installed in your account, switch to the application owner role first. | ||
|
||
### Calling a stored procedure | ||
|
||
``` | ||
CALL <your_application_name>.<schema_name>.<stored_procedure_name_with_args>; | ||
``` | ||
|
||
### Calling a function | ||
|
||
``` | ||
SELECT <your_application_name>.<schema_name>.<udf_with_args>; | ||
``` |
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,9 @@ | ||
# This is a manifest.yml file, a required component of creating a Snowflake Native App. | ||
# This file defines properties required by the application package, including the location of the setup script and version definitions. | ||
# Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-manifest for a detailed understanding of this file. | ||
|
||
manifest_version: 1 | ||
|
||
artifacts: | ||
setup_script: setup_script.sql | ||
readme: README.md |
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,11 @@ | ||
-- This is the setup script that runs while installing a Snowflake Native App in a consumer account. | ||
-- To write this script, you can familiarize yourself with some of the following concepts: | ||
-- Application Roles | ||
-- Versioned Schemas | ||
-- UDFs/Procs | ||
-- Extension Code | ||
-- Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-setup-script for a detailed understanding of this file. | ||
|
||
CREATE OR ALTER VERSIONED SCHEMA core; | ||
|
||
-- The rest of this script is left blank for purposes of your learning and exploration. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update the version to replace
version 3.x.x
when this feature is included in a release.