gatus icon indicating copy to clipboard operation
gatus copied to clipboard

Add support for MariaDB/MySQL

Open Matir opened this issue 2 years ago • 4 comments

Describe the feature request

sqlite and postgres are both available as storage engines. In some environments, where a MySQL or MariaDB server already exists, it would be convenient to use a DB on this server.

Why do you personally want this feature to be implemented?

I have an environment with MySQL/MariaDB :)

How long have you been using this project?

Currently evaluating

Additional information

If there are no known technical blockers why it would not work, I'm happy to take a pass at implementing the support and send a PR. It looks like it should be fairly doable, and would be in the same style as the postgres/sqlite split.

Matir avatar May 10 '22 17:05 Matir

Sounds good to me!

It may be a bit tricky though, because IIRC, mysql/mariadb does not support the following:

  • INSERT INTO ... RETURNING <column_name>
  • INSERT INTO ... ON CONFLICT(...) DO UPDATE

TwiN avatar May 13 '22 01:05 TwiN

  • INSERT INTO ... RETURNING <column_name>

Mariadb (not MySQL) has RETURNING since 10.5, though if you just want to get a new primary key back older versions and MySQL have SELECT LAST_INSERT_ID() which operates per session. (i.e. you are guaranteed to get the last new primary key generated on your current session)

  • INSERT INTO ... ON CONFLICT(...) DO UPDATE

MySQL/MariaDB you have two options to do something similar:

REPLACE INTO -> simpler if you just want to overwrite an old row

or

INSERT ... ON DUPLICATE KEY UPDATE -> more flexible if you, e.g. want to increment a counter

HTH!

mrmonkington avatar Sep 27 '22 11:09 mrmonkington