Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sirwanafifi/mysql-actions
MySQL Actions
https://github.com/sirwanafifi/mysql-actions
actions golang mysql yaml
Last synced: 7 days ago
JSON representation
MySQL Actions
- Host: GitHub
- URL: https://github.com/sirwanafifi/mysql-actions
- Owner: SirwanAfifi
- License: apache-2.0
- Created: 2023-10-01T21:16:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-02T20:00:08.000Z (about 1 year ago)
- Last Synced: 2024-06-21T18:55:09.921Z (5 months ago)
- Topics: actions, golang, mysql, yaml
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MySQL Actions
This is a lot like GitHub Actions; Let's say you have a MySQL database with tables and you want something to happen when a new row is added, changed, or deleted, this is for you. For example, if you have a table of users and want a message to show up when a new user is inserted or deleted, you can set that up with a YAML file.
```yaml
name: Send Notification Exampleon:
insert:
tables:
- users
delete:
tables:
- usersjobs:
- name: Send Notification
steps:
- name: Run send_notification.sh script
shell: bash
# run: ./send_notification.sh
run: |
echo "Hello World"
```This then prints "Hello World" when a new user is created or deleted.
## Running
Make sure you have a MySQL server running and you have set the these environment variables in a `.env` file:
```bash
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_HOST=
MYSQL_DB=
```Then run the following command to start the application:
```bash
> go run ./cmd/mysql-actions/main.go
```## How it works
The application basically uses MySQL triggers. Upon startup, it creates a table called `event_log` along with triggers for each table specified in the YAML file. When a row is either inserted or deleted from the tables, the corresponding trigger inserts a new record to the `event_log`. Subsequently, the application scans the `event_log` at regular intervals for new entries and executes the script delineated in the YAML file.