Skip to content

Commit

Permalink
DVO-5131 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco authored Sep 9, 2024
1 parent 8bc66dd commit 24b1f65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ runs:
run: |
echo "Inputs validation failed."
exit 1
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate with DEV
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -59,3 +56,12 @@ runs:
ACTION: ${{ inputs.branch_action }}
shell: bash
run: bash ${{ github.action_path }}/script.sh

- name: Upload Dump.sql
if: success() || failure()
uses: actions/upload-artifact@v4
with:
path: dump.sql
name: dump-sql
retention-days: 1
if-no-files-found: ignore
14 changes: 7 additions & 7 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ elif [[ $ACTION = "Create" ]] || [[ $ACTION = "Recreate" ]]; then
createdb --owner=dev_role -h $DBHOST -U $DBUSERNAME $DATABASE --template=template0 --lc-collate=en_US.utf8 --lc-ctype=en_US.utf8 --encoding=UTF-8
pg_dump --exclude-table-data=audit.audit_log_* --exclude-table-data=audit.page_view_* --exclude-table=public.data_change_staging* --disable-triggers --no-owner -h $DBHOST -U $DBUSERNAME -d $SOURCE_DB > dump.sql
sed -i '1s/^/SET ROLE dev_role;\n/' dump.sql
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -f dump.sql
psql -h $DBHOST -U $DBUSERNAME -d control_center -c "insert into log.branch_database (database_name, created_by_user, source_database) values ('$DATABASE', '$USERNAME', '$SOURCE_DB');"
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -c "CREATE EVENT TRIGGER trigger_alter_ownership ON ddl_command_end when tag in ('CREATE TABLE', 'CREATE VIEW', 'CREATE MATERIALIZED VIEW', 'CREATE FUNCTION', 'CREATE INDEX') EXECUTE PROCEDURE db_admin.alter_ownership();"
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -c "GRANT CREATE ON DATABASE \"$DATABASE\" TO dev_role, liquibase_deploy_user;"
rm -f dump.sql
echo "Database created."
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -f dump.sql -b
psql -h $DBHOST -U $DBUSERNAME -d control_center -c "insert into log.branch_database (database_name, created_by_user, source_database) values ('$DATABASE', '$USERNAME', '$SOURCE_DB');" -b
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -c "CREATE EVENT TRIGGER trigger_alter_ownership ON ddl_command_end when tag in ('CREATE TABLE', 'CREATE VIEW', 'CREATE MATERIALIZED VIEW', 'CREATE FUNCTION', 'CREATE INDEX') EXECUTE PROCEDURE db_admin.alter_ownership();" -b
psql -h $DBHOST -U $DBUSERNAME -d $DATABASE -c "GRANT CREATE ON DATABASE \"$DATABASE\" TO dev_role, liquibase_deploy_user;" -b

echo "Database created."
fi
fi
fi

0 comments on commit 24b1f65

Please sign in to comment.