From 0f1a7c024d49738301df36e6e5213b4561df20eb Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Thu, 5 Sep 2024 11:46:14 +0800 Subject: [PATCH] chore(ci): reset users midnight utc --- .github/workflows/reset-users.yml | 26 ++++++++++++++++++++++++++ bin/reset-users.mongodb.js | 11 +++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/reset-users.yml create mode 100644 bin/reset-users.mongodb.js diff --git a/.github/workflows/reset-users.yml b/.github/workflows/reset-users.yml new file mode 100644 index 0000000..7e2464b --- /dev/null +++ b/.github/workflows/reset-users.yml @@ -0,0 +1,26 @@ +name: Reset users + +on: + workflow_dispatch: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '0 0 * * *' +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout this repo + uses: actions/checkout@v4 + - name: 🍃 Install mongosh + run: | + sudo apt-get update + sudo apt-get install -y wget gnupg + wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list + sudo apt-get update + sudo apt-get install -y mongodb-mongosh + - name: Reset mongo + env: + DB_URI: ${{ secrets.DB_URI }} + run: | + mongosh -f bin/reset-users.mongodb.js $DB_URI diff --git a/bin/reset-users.mongodb.js b/bin/reset-users.mongodb.js new file mode 100644 index 0000000..d4eefb3 --- /dev/null +++ b/bin/reset-users.mongodb.js @@ -0,0 +1,11 @@ +/* eslint-disable */ + +print( + db.users + .find({}) + .sort({ lastAccessed: 1 }) + .project({ _id: 0, created: 1, lastAccessed: 1, updatedAt: 1 }) +) + +db.sessions.deleteMany({ }) +db.users.deleteMany({ })