Skip to content

Instantly share code, notes, and snippets.

@metaperl
metaperl / audit_mixin.py
Last active February 14, 2022 11:28
generic audit log for SQLAlchemy models, inspired by https://gist.github.com/ngse/c20058116b8044c65d3fbceda3fdf423
# Inspired by the flask-specific https://gist.github.com/ngse/c20058116b8044c65d3fbceda3fdf423
# This is generic and should work with any web framework and even command-line.
# Implement by using AuditableMixin in your model class declarations
# Usage for the [Reahl web app framework](http://reahl.org) below:
# ---------------------------------------------------------------
# import lib.audit_mixin
#!/bin/bash
if [[ $DEBUG == "true" ]]; then
set -x
fi
# Check if FQDN is given
if [ -z "$1" ]; then
echo "Usage: $0 rancher.yourdomain.com"
exit 1
fi
@ngse
ngse / audit_mixin.py
Last active May 21, 2023 13:56
Rough attempt at implementing an audit log against Flask/Flask Login/SQLAlchemy models
# Requires use of Flask Login for the user tracking
# Implement by using AuditableMixin in your model class declarations
# e.g. class ImportantThing(AuditableMixin, Base):
import json
from flask_login import current_user
from sqlalchemy import event, inspect
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.attributes import get_history

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@NYKevin
NYKevin / accounting.sql
Last active April 3, 2024 15:46
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...