-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1621763 update example for na + spcs upgrade
- Loading branch information
Yong Xu
committed
Aug 14, 2024
1 parent
c7c986c
commit 95dc76e
Showing
7 changed files
with
229 additions
and
47 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
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
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,48 @@ | ||
manifest_version: 2 | ||
version: | ||
name: versioned_schema | ||
label: "Second Version" | ||
|
||
artifacts: | ||
setup_script: setup.sql | ||
|
||
default_web_endpoint: | ||
service: app_public.frontend | ||
endpoint: app | ||
|
||
container_services: | ||
images: | ||
- /spcs_app/napp/img_repo/eap_frontend | ||
- /spcs_app/napp/img_repo/eap_backend | ||
- /spcs_app/napp/img_repo/eap_router | ||
|
||
lifecycle_callbacks: | ||
version_initializer: versioned_schema.init | ||
|
||
privileges: | ||
- BIND SERVICE ENDPOINT: | ||
description: "Ability to create ingress URLs." | ||
required_at_setup: true | ||
- CREATE COMPUTE POOL: | ||
required_at_setup: true | ||
description: "Enable appplication to create its own compute pool(s)" | ||
|
||
|
||
references: | ||
- ORDERS_TABLE: | ||
label: "Orders table" | ||
description: "Orders table in TPC-H samples" | ||
privileges: | ||
- SELECT | ||
object_type: VIEW | ||
multi_valued: false | ||
register_callback: versioned_schema.register_single_callback | ||
|
||
- WIKIPEDIA_EAI: | ||
label: "Wikipedia Access Integration" | ||
description: "EAI for Egress from NA+SPCS" | ||
privileges: [USAGE] | ||
object_type: EXTERNAL_ACCESS_INTEGRATION | ||
register_callback: versioned_schema.register_single_callback | ||
configuration_callback: versioned_schema.get_configuration | ||
required_at_setup: true |
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,154 @@ | ||
CREATE APPLICATION ROLE IF NOT EXISTS app_admin; | ||
CREATE APPLICATION ROLE IF NOT EXISTS app_user; | ||
CREATE SCHEMA IF NOT EXISTS app_public; | ||
GRANT USAGE ON SCHEMA app_public TO APPLICATION ROLE app_admin; | ||
GRANT USAGE ON SCHEMA app_public TO APPLICATION ROLE app_user; | ||
CREATE OR ALTER VERSIONED SCHEMA versioned_schema; | ||
GRANT USAGE ON SCHEMA versioned_schema TO APPLICATION ROLE app_admin; | ||
|
||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.register_single_callback(ref_name STRING, operation STRING, ref_or_alias STRING) | ||
RETURNS STRING | ||
LANGUAGE SQL | ||
AS $$ | ||
BEGIN | ||
CASE (operation) | ||
WHEN 'ADD' THEN | ||
SELECT system$set_reference(:ref_name, :ref_or_alias); | ||
WHEN 'REMOVE' THEN | ||
SELECT system$remove_reference(:ref_name); | ||
WHEN 'CLEAR' THEN | ||
SELECT system$remove_reference(:ref_name); | ||
ELSE | ||
RETURN 'Unknown operation: ' || operation; | ||
END CASE; | ||
RETURN 'Operation ' || operation || ' succeeds.'; | ||
END; | ||
$$; | ||
GRANT USAGE ON PROCEDURE versioned_schema.register_single_callback(STRING, STRING, STRING) TO APPLICATION ROLE app_admin; | ||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.get_configuration(ref_name STRING) | ||
RETURNS STRING | ||
LANGUAGE SQL | ||
AS | ||
$$ | ||
BEGIN | ||
CASE (UPPER(ref_name)) | ||
WHEN 'WIKIPEDIA_EAI' THEN | ||
RETURN OBJECT_CONSTRUCT( | ||
'type', 'CONFIGURATION', | ||
'payload', OBJECT_CONSTRUCT( | ||
'host_ports', ARRAY_CONSTRUCT('upload.wikimedia.org'), | ||
'allowed_secrets', 'NONE') | ||
)::STRING; | ||
ELSE | ||
RETURN ''; | ||
END CASE; | ||
END; | ||
$$; | ||
|
||
GRANT USAGE ON PROCEDURE versioned_schema.get_configuration(STRING) TO APPLICATION ROLE app_admin; | ||
|
||
-- The version initializer callback is executed after a successful installation, upgrade, or downgrade of an application object. | ||
-- In case the application fails to upgrade, the version initializer of the previous (successful) version will be executed so you | ||
-- can clean up application state that may have been modified during the failed upgrade. | ||
CREATE OR REPLACE PROCEDURE versioned_schema.init() | ||
RETURNS STRING | ||
LANGUAGE SQL | ||
EXECUTE AS OWNER | ||
AS | ||
$$ | ||
BEGIN | ||
ALTER SERVICE IF EXISTS app_public.frontend FROM SPECIFICATION_FILE='frontend.yaml'; | ||
ALTER SERVICE IF EXISTS app_public.backend FROM SPECIFICATION_FILE='backend.yaml'; | ||
GRANT SERVICE ROLE app_public.frontend!ALL_ENDPOINTS_USAGE TO APPLICATION ROLE app_admin; | ||
RETURN 'init complete'; | ||
END $$; | ||
|
||
GRANT USAGE ON PROCEDURE versioned_schema.init() TO APPLICATION ROLE app_admin; | ||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.start_backend(pool_name VARCHAR) | ||
RETURNS string | ||
LANGUAGE sql | ||
AS $$ | ||
BEGIN | ||
CREATE SERVICE IF NOT EXISTS app_public.backend | ||
IN COMPUTE POOL Identifier(:pool_name) | ||
FROM SPECIFICATION_FILE='backend.yaml' | ||
QUERY_WAREHOUSE = 'WH_NAC'; | ||
GRANT USAGE ON SERVICE app_public.backend TO APPLICATION ROLE app_user; | ||
END | ||
$$; | ||
GRANT USAGE ON PROCEDURE versioned_schema.start_backend(VARCHAR) TO APPLICATION ROLE app_admin; | ||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.start_frontend(pool_name VARCHAR) | ||
RETURNS string | ||
LANGUAGE sql | ||
AS $$ | ||
BEGIN | ||
CREATE SERVICE IF NOT EXISTS app_public.frontend | ||
IN COMPUTE POOL Identifier(:pool_name) | ||
FROM SPECIFICATION_FILE='frontend.yaml' | ||
EXTERNAL_ACCESS_INTEGRATIONS=( reference('WIKIPEDIA_EAI') ); | ||
|
||
GRANT USAGE ON SERVICE app_public.frontend TO APPLICATION ROLE app_user; | ||
|
||
RETURN 'Service started. Check status, and when ready, get URL'; | ||
END | ||
$$; | ||
GRANT USAGE ON PROCEDURE versioned_schema.start_frontend(VARCHAR) TO APPLICATION ROLE app_admin; | ||
|
||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.create_services(privileges array) | ||
RETURNS STRING | ||
LANGUAGE SQL | ||
AS | ||
$$ | ||
BEGIN | ||
CREATE COMPUTE POOL IF NOT EXISTS frontend_compute_pool | ||
MIN_NODES = 1 | ||
MAX_NODES = 1 | ||
INSTANCE_FAMILY = CPU_X64_XS; | ||
|
||
CREATE COMPUTE POOL IF NOT EXISTS backend_compute_pool | ||
MIN_NODES = 1 | ||
MAX_NODES = 1 | ||
INSTANCE_FAMILY = CPU_X64_XS; | ||
|
||
CALL versioned_schema.start_backend('backend_compute_pool'); | ||
CALL versioned_schema.start_frontend('frontend_compute_pool'); | ||
END; | ||
$$; | ||
GRANT USAGE ON PROCEDURE versioned_schema.create_services(array) TO APPLICATION ROLE app_admin; | ||
|
||
|
||
CREATE OR REPLACE PROCEDURE app_public.stop_app() | ||
RETURNS string | ||
LANGUAGE sql | ||
AS | ||
$$ | ||
BEGIN | ||
DROP SERVICE IF EXISTS app_public.backend; | ||
DROP SERVICE IF EXISTS app_public.frontend; | ||
END | ||
$$; | ||
GRANT USAGE ON PROCEDURE app_public.stop_app() TO APPLICATION ROLE app_admin; | ||
|
||
CREATE OR REPLACE PROCEDURE versioned_schema.app_url() | ||
RETURNS string | ||
LANGUAGE sql | ||
AS | ||
$$ | ||
DECLARE | ||
ingress_url VARCHAR; | ||
BEGIN | ||
SHOW ENDPOINTS IN SERVICE app_public.frontend; | ||
SELECT "ingress_url" INTO :ingress_url FROM TABLE (RESULT_SCAN (LAST_QUERY_ID())) LIMIT 1; | ||
RETURN ingress_url; | ||
END | ||
$$; | ||
GRANT USAGE ON PROCEDURE versioned_schema.app_url() TO APPLICATION ROLE app_admin; | ||
GRANT USAGE ON PROCEDURE versioned_schema.app_url() TO APPLICATION ROLE app_user; | ||
|
||
-- Support functions | ||
EXECUTE IMMEDIATE FROM 'support.sql'; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
USE ROLE nac; | ||
USE WAREHOUSE wh_nac; | ||
GRANT USAGE ON WAREHOUSE wh_nac TO APPLICATION spcs_app_instance; | ||
CALL spcs_app_instance.v1.register_single_callback('ORDERS_TABLE' , 'ADD', SYSTEM$REFERENCE('VIEW', 'NAC_TEST.DATA.ORDERS', 'PERSISTENT', 'SELECT')); | ||
CALL spcs_app_instance.versioned_schema.register_single_callback('ORDERS_TABLE' , 'ADD', SYSTEM$REFERENCE('VIEW', 'NAC_TEST.DATA.ORDERS', 'PERSISTENT', 'SELECT')); |
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