Skip to content

Commit

Permalink
chore: database recreation scripts (commune-sh#5)
Browse files Browse the repository at this point in the history
<!--
Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->

Provides scripts to backup, restore and clear Synapse database
  • Loading branch information
EstebanBorai authored Dec 2, 2023
1 parent 5222016 commit 88fd973
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ jobs:
- name: Check Synapse is Running
run: curl -sSf http://localhost:8008 > /dev/null

- name: Provide Database Backup & Test it
run: |
just backup_db
just nuke_db
just restore_db
- name: Retrieve Admin Access Token
run: |
just get_access_token
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Cargo.lock
!/docker/postgre
.env
access_token.txt
dump.sql

# System Specific
.DS_Store
15 changes: 15 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ default:
dotenv:
cp -n .env.example .env || true

# Dump database to a file
backup_db:
docker compose exec -T synapse_database \
pg_dumpall -c -U synapse_user > ./dump.sql

# Restore database from a file
restore_db:
cat ./dump.sql | docker compose exec -T synapse_database \
psql -U synapse_user -d synapse

# Nuke database
nuke_db:
docker compose exec -T synapse_database \
psql -U synapse_user -d synapse -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"

# Generates the synapse configuration file and saves it
gen_synapse_conf: dotenv
docker run -i --rm \
Expand Down

0 comments on commit 88fd973

Please sign in to comment.