albertcito / postgresql-audit Goto Github PK
View Code? Open in Web Editor NEWLog for your tables in postgreSQL. Add trigger to Insert, update and delete every row in each table. And insert it in the audit table
License: MIT License
Log for your tables in postgreSQL. Add trigger to Insert, update and delete every row in each table. And insert it in the audit table
License: MIT License
audit_table_copy(destiny_name_db varchar , name_schema varchar , name_table varchar)
get_columns(schema, table)
and create table (created in issue #1)Add this columns:
Updated table log if the original table has a new column.
the audit
tablesaudit_db()
Updated table log if the original table changed the column data type. For instance: varchar 255 to text.
audit_table_triggers(destiny_name_db varchar, name_schema varchar, name_table varchar)
This function creates or updated a trigger in the name_table to insert a new row in its log table each time that a new row is updated, inserted or deleted in this table.
audit_schema(name_schema)
(schema, table) => return all columns and it's type of the table.
The db by default has lang
table. You can do it with that table.
This is a code that I made long time ago about a function in Postgres. You will ned to use the information_schema to get the table columns information.
Inside of the folder db_init
create a new file called get_table_colums_data.sql
.
CREATE OR REPLACE FUNCTION get_table_colums_data (name_schema varchar, name_table varchar)
RETURNS TABLE (
column_name information_schema.columns.column_name%TYPE,
data_type information_schema.columns.data_type%TYPE,
character_maximum_length information_schema.columns.character_maximum_length%TYPE,
numeric_precision information_schema.columns.numeric_precision%TYPE,
datetime_precision information_schema.columns.datetime_precision%TYPE
)
AS $func$
BEGIN
RETURN QUERY
SELECT
columns.column_name,
columns.data_type,
columns.character_maximum_length,
columns.numeric_precision,
columns.datetime_precision
FROM
information_schema.columns
WHERE
columns.table_schema = name_schema
AND columns.table_name = name_table
ORDER BY
ordinal_position ASC;
END
$func$
LANGUAGE plpgsql;
Test it: SELECT * FROM audit_get_table_columns('public', 'lang');
audit_table(name_schema varchar, name_table varchar)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.