flask-postgresql-audit 1.0.3__tar.gz → 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/PKG-INFO +1 -1
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/__init__.py +1 -1
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/alembic/entities.py +9 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/alembic/setup.py +1 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/base.py +1 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/create_activity.sql +6 -3
- flask_postgresql_audit-1.0.4/flask_postgresql_audit/templates/get_pk_values.sql +22 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/test_defaults.py +1 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/.gitignore +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/CHANGES.md +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/LICENSE +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/README.md +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/alembic/__init__.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/alembic/schema.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/core.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/models.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/audit_trigger_delete.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/audit_trigger_insert.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/audit_trigger_update.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/create_schema.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/drop_schema.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/get_setting.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/jsonb_subtract.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/row_audit_trigger.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/templates/row_create_activity.sql +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/typing.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/utils.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/pyproject.toml +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/__init__.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/app.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/conftest.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/migrations/README +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/migrations/alembic.ini +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/migrations/env.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/migrations/script.py.mako +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/test_operators.py +0 -0
- {flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flask-postgresql_audit
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: Versioning and auditing extension for PostgreSQL and SQLAlchemy.
|
|
5
5
|
Project-URL: Homepage, https://github.com/higamigu/flask-postgresql-audit
|
|
6
6
|
Author-email: Higamigu <higamigu@gmail.com>, Konsta Vesterinen <konsta@fastmonkeys.com>
|
|
@@ -46,6 +46,15 @@ def trigger_update_factory(**context):
|
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
def get_pk_values(**context):
|
|
50
|
+
sql = parse_template("get_pk_values.sql", **context)
|
|
51
|
+
return PGFunction(
|
|
52
|
+
schema=context["schema_name"],
|
|
53
|
+
signature="get_pk_values(relid oid, row_data jsonb)",
|
|
54
|
+
definition=sql["definition"],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
49
58
|
def get_setting_factory(**context):
|
|
50
59
|
sql = parse_template("get_setting.sql", **context)
|
|
51
60
|
return PGFunction(
|
|
@@ -62,6 +62,7 @@ def setup_db(audit: "PostgreSQLAudit"):
|
|
|
62
62
|
|
|
63
63
|
def register_core_entities(audit: "PostgreSQLAudit"):
|
|
64
64
|
audit.pg_audit_entities.add(entities.btree_gist)
|
|
65
|
+
audit.pg_audit_entities.add(entities.get_pk_values(**audit.context))
|
|
65
66
|
audit.pg_audit_entities.add(entities.get_setting_factory(**audit.context))
|
|
66
67
|
audit.pg_audit_entities.add(entities.jsonb_subtract_factory(**audit.context))
|
|
67
68
|
audit.pg_audit_entities.add(entities.create_activity_factory(**audit.context))
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/base.py
RENAMED
|
@@ -22,6 +22,7 @@ class ActivityBase:
|
|
|
22
22
|
native_transaction_id: OMap[int] = mapped_column(BigInteger, index=True)
|
|
23
23
|
verb: OMap[str] = mapped_column(Text)
|
|
24
24
|
|
|
25
|
+
row_key: OMap[list[str]] = mapped_column(JSONB, default=[], server_default="[]")
|
|
25
26
|
old_data: OMap[dict] = mapped_column(JSONB, default={}, server_default="{}")
|
|
26
27
|
changed_data: OMap[dict] = mapped_column(JSONB, default={}, server_default="{}")
|
|
27
28
|
|
|
@@ -20,7 +20,7 @@ BEGIN
|
|
|
20
20
|
IF (TG_OP = 'UPDATE') THEN
|
|
21
21
|
INSERT INTO ${schema_prefix}pga_activity(
|
|
22
22
|
id, schema_name, table_name, relid, issued_at, native_transaction_id,
|
|
23
|
-
verb, old_data, changed_data, transaction_id)
|
|
23
|
+
verb, row_key, old_data, changed_data, transaction_id)
|
|
24
24
|
SELECT
|
|
25
25
|
nextval('${schema_prefix}pga_activity_id_seq') as id,
|
|
26
26
|
TG_TABLE_SCHEMA::text AS schema_name,
|
|
@@ -29,6 +29,7 @@ BEGIN
|
|
|
29
29
|
statement_timestamp() AT TIME ZONE 'UTC' AS issued_at,
|
|
30
30
|
txid_current() AS native_transaction_id,
|
|
31
31
|
LOWER(TG_OP) AS verb,
|
|
32
|
+
${schema_prefix}get_pk_values(TG_RELID, new_data) AS row_key,
|
|
32
33
|
old_data - excluded_cols AS old_data,
|
|
33
34
|
${schema_prefix}jsonb_subtract(new_data, old_data) - excluded_cols AS changed_data,
|
|
34
35
|
_transaction_id AS transaction_id
|
|
@@ -48,7 +49,7 @@ BEGIN
|
|
|
48
49
|
ELSIF (TG_OP = 'INSERT') THEN
|
|
49
50
|
INSERT INTO ${schema_prefix}pga_activity(
|
|
50
51
|
id, schema_name, table_name, relid, issued_at, native_transaction_id,
|
|
51
|
-
verb, old_data, changed_data, transaction_id)
|
|
52
|
+
verb, row_key, old_data, changed_data, transaction_id)
|
|
52
53
|
SELECT
|
|
53
54
|
nextval('${schema_prefix}pga_activity_id_seq') as id,
|
|
54
55
|
TG_TABLE_SCHEMA::text AS schema_name,
|
|
@@ -57,6 +58,7 @@ BEGIN
|
|
|
57
58
|
statement_timestamp() AT TIME ZONE 'UTC' AS issued_at,
|
|
58
59
|
txid_current() AS native_transaction_id,
|
|
59
60
|
LOWER(TG_OP) AS verb,
|
|
61
|
+
${schema_prefix}get_pk_values(TG_RELID, to_jsonb(new_table)) AS row_key,
|
|
60
62
|
'{}'::jsonb AS old_data,
|
|
61
63
|
row_to_json(new_table.*)::jsonb - excluded_cols AS changed_data,
|
|
62
64
|
_transaction_id AS transaction_id
|
|
@@ -64,7 +66,7 @@ BEGIN
|
|
|
64
66
|
ELSEIF TG_OP = 'DELETE' THEN
|
|
65
67
|
INSERT INTO ${schema_prefix}pga_activity(
|
|
66
68
|
id, schema_name, table_name, relid, issued_at, native_transaction_id,
|
|
67
|
-
verb, old_data, changed_data, transaction_id)
|
|
69
|
+
verb, row_key, old_data, changed_data, transaction_id)
|
|
68
70
|
SELECT
|
|
69
71
|
nextval('${schema_prefix}pga_activity_id_seq') as id,
|
|
70
72
|
TG_TABLE_SCHEMA::text AS schema_name,
|
|
@@ -73,6 +75,7 @@ BEGIN
|
|
|
73
75
|
statement_timestamp() AT TIME ZONE 'UTC' AS issued_at,
|
|
74
76
|
txid_current() AS native_transaction_id,
|
|
75
77
|
LOWER(TG_OP) AS verb,
|
|
78
|
+
${schema_prefix}get_pk_values(TG_RELID, to_jsonb(old_table)) AS row_key,
|
|
76
79
|
row_to_json(old_table.*)::jsonb - excluded_cols AS old_data,
|
|
77
80
|
'{}'::jsonb AS changed_data,
|
|
78
81
|
_transaction_id AS transaction_id
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
CREATE OR REPLACE FUNCTION get_pk_values(relid oid, row_data jsonb) RETURNS jsonb AS $$
|
|
2
|
+
DECLARE
|
|
3
|
+
pk_columns text [];
|
|
4
|
+
pk_values jsonb;
|
|
5
|
+
BEGIN
|
|
6
|
+
SELECT array_agg(a.attname ORDER BY a.attnum) INTO pk_columns
|
|
7
|
+
FROM pg_index i
|
|
8
|
+
JOIN pg_attribute a ON a.attrelid = i.indrelid
|
|
9
|
+
AND a.attnum = ANY(i.indkey)
|
|
10
|
+
WHERE i.indrelid = relid
|
|
11
|
+
AND i.indisprimary;
|
|
12
|
+
|
|
13
|
+
IF pk_columns IS NULL THEN
|
|
14
|
+
RETURN '{}'::jsonb;
|
|
15
|
+
END IF;
|
|
16
|
+
|
|
17
|
+
SELECT jsonb_agg(row_data->>col) INTO pk_values
|
|
18
|
+
FROM unnest(pk_columns) AS col;
|
|
19
|
+
|
|
20
|
+
RETURN pk_values;
|
|
21
|
+
END;
|
|
22
|
+
$$ LANGUAGE plpgsql;
|
|
@@ -9,6 +9,7 @@ class TestCustomSchemaactivityCreation:
|
|
|
9
9
|
def test_insert(self, user):
|
|
10
10
|
stmt = sa.select(audit.Activity).limit(1)
|
|
11
11
|
if activity := db.session.scalar(stmt):
|
|
12
|
+
assert activity.row_key == ["1"]
|
|
12
13
|
assert activity.old_data == {}
|
|
13
14
|
assert activity.changed_data == {"id": user.id, "name": "John", "age": 15}
|
|
14
15
|
assert activity.table_name == "user"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/core.py
RENAMED
|
File without changes
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/models.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/typing.py
RENAMED
|
File without changes
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/flask_postgresql_audit/utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flask_postgresql_audit-1.0.3 → flask_postgresql_audit-1.0.4}/tests/migrations/script.py.mako
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|