aileftech / snap-admin

A plug-and-play, auto-generated CRUD database admin panel for Spring Boot apps
MIT License
256 stars 20 forks source link

Add event logging to DB? #48

Open ochompsky opened 2 months ago

ochompsky commented 2 months ago

It looks like it logs to a local h2 db, which is not ideal for docker containers without persistant storage. I wonder the feasibility of logging to an actual db server?

I'm going to play around with SnapAdminAutoConfiguration as that seems to be the place to do these changes.

Are you able to provide the DDL for internal table structures?

ochompsky commented 2 months ago

i've forked a version of this here https://github.com/ochompsky/snap-admin/tree/main

in that version, it will allow for a remotely specified db connection. in your properties you will need something like:

internal:
  datasource:
    driver-class-name: "org.postgresql.Driver"
    url: "jdbc:postgresql://server:5432/postgres"
    username: "user"
    password: "pass"
    hibernate-dialect: "org.hibernate.dialect.PostgreSQLDialect"
    hbm2ddl-auto: update

note that i've only tested it with postgres. i know for a fact it will not work with mysql because the column sql needs to be renamed. EDIT: i've also renamed it so now it should work with all common databases, but haven't tried h2 yet.

im not submitting a PR because it's a breaking change and really this needs to be changed to work with all common remote db's

EDIT2: @aileftech - do you want me to submit a PR? i've tested this change with the default H2, Postgres as well as MYSQL and it appears to work. the only downside is that will require a user to specify which one to use out of the box, i haven't implemented any default. but there's no reason they can't add the below properties along with other snapadmin ones:

internal:
  datasource:
    driver-class-name: "org.h2.Driver"
    url: "jdbc:h2:file:./snapadmin_internal"
    username: "sa"
    password: "password"
    hibernate-dialect: "org.hibernate.dialect.H2Dialect"
    hbm2ddl-auto: update