Skip to content

Commit

Permalink
Ignore permisison errors creating Snowflake schema
Browse files Browse the repository at this point in the history
Update the Snowflake registry creation scripts to ignore permission
errors when creating or commenting on the registry schema, to account
for the case where the schema already exists but the current user does
not have permission to execute `CREATE SCHEMA`. Suggested by Peter
Wimsey (resolves #826).
  • Loading branch information
theory committed Dec 31, 2024
1 parent 2b77698 commit cbc5d6d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Revision history for Perl extension App::Sqitch
Exasol and because `FAILURE` maps to exit code `1`, which has in the
past been more akin to a warning from Sqitch. Thanks to @vectro for the
report (#831).
- Updated the Snowflake registry creation scripts to ignore permission
errors when creating or commenting on the registry schema, to account
for the case where the schema already exists but the current user does
not have permission to execute `CREATE SCHEMA`. Suggested by Peter
Wimsey (#826).

1.4.1 2024-02-04T16:35:32Z
- Removed the quoting of the role and warehouse identifiers that was
Expand Down
8 changes: 7 additions & 1 deletion lib/App/Sqitch/Engine/Upgrade/snowflake-1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ UPDATE &registry.changes SET script_hash = change_id;
ALTER TABLE &registry.changes ADD UNIQUE(script_hash);
COMMENT ON COLUMN &registry.changes.script_hash IS 'Deploy script SHA-1 hash.';

COMMENT ON SCHEMA &registry IS 'Sqitch database deployment metadata v1.0.';
EXECUTE IMMEDIATE $$
BEGIN
COMMENT ON SCHEMA &registry IS 'Sqitch database deployment metadata v1.0.';
EXCEPTION WHEN statement_error THEN
IF (sqlstate = '42501') THEN RETURN ''; END IF;
END;
$$;
8 changes: 7 additions & 1 deletion lib/App/Sqitch/Engine/Upgrade/snowflake-1.1.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ALTER TABLE &registry.changes DROP UNIQUE(script_hash);
ALTER TABLE &registry.changes ADD UNIQUE(project, script_hash);
COMMENT ON SCHEMA &registry IS 'Sqitch database deployment metadata v1.0.';
EXECUTE IMMEDIATE $$
BEGIN
COMMENT ON SCHEMA &registry IS 'Sqitch database deployment metadata v1.1.';
EXCEPTION WHEN statement_error THEN
IF (sqlstate = '42501') THEN RETURN ''; END IF;
END;
$$;
12 changes: 9 additions & 3 deletions lib/App/Sqitch/Engine/snowflake.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CREATE SCHEMA IF NOT EXISTS &registry;

COMMENT ON SCHEMA &registry IS 'Sqitch database deployment metadata v1.1.';
-- Create the schema but ignore permission errors
EXECUTE IMMEDIATE $$
BEGIN
CREATE SCHEMA IF NOT EXISTS identifier('&registry');
COMMENT ON SCHEMA identifier('&registry') IS 'Sqitch database deployment metadata v1.1.';
EXCEPTION WHEN statement_error THEN
IF (sqlstate = '42501') THEN RETURN ''; END IF;
END;
$$;

CREATE TABLE &registry.releases (
version FLOAT PRIMARY KEY,
Expand Down

0 comments on commit cbc5d6d

Please sign in to comment.