From a74bc62336332fed5af26be8b0454e627ac14d2a Mon Sep 17 00:00:00 2001 From: Colin Murtaugh Date: Fri, 7 Jun 2024 14:21:40 -0400 Subject: [PATCH] create instructure_dap schema and grant canvas user create permissions --- prepare_aurora_db.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/prepare_aurora_db.py b/prepare_aurora_db.py index 3d7bb58..c0052eb 100755 --- a/prepare_aurora_db.py +++ b/prepare_aurora_db.py @@ -138,3 +138,36 @@ except ClientError as e: console.print(f" ! Unexpected error creating schema {username}: {e}", style="bold red") continue + + # create the instructure_dap schema + try: + schema_sql = f"CREATE SCHEMA IF NOT EXISTS instructure_dap AUTHORIZATION {username}" + rds_data_client.execute_statement( + resourceArn=aurora_cluster_arn, + secretArn=admin_secret_arn, + sql=schema_sql, + database=database_name, + ) + console.print( + f" - Created schema [bold]instructure_dap[/bold] in database [bold]{database_name}[/bold]", + style="green", + ) + except ClientError as e: + console.print(f" ! Unexpected error: {e}", style="bold red") + continue + + # grant create permission on database to canvas user + try: + grant_sql = f"GRANT CREATE ON DATABASE {database_name} TO {username}" + rds_data_client.execute_statement( + resourceArn=aurora_cluster_arn, + secretArn=admin_secret_arn, + sql=grant_sql, + database="postgres", + ) + console.print( + f" - Granted CREATE on database {database_name} to user {username}", + style="bold green", + ) + except ClientError as e: + console.print(f" ! Unexpected error: {e}", style="bold red")