Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: update sample schema (#13157)
Tianzhou (天舟)d90286ba6584
diff --git a/backend/demo/data/default/README.md b/backend/demo/data/default/README.mdindex 350b17f089..0ed85933ac 100644--- a/backend/demo/data/default/README.md+++ b/backend/demo/data/default/README.md@@ -1,8 +1,6 @@# Overview-_Work In Progress_--This is the next version of demo data for https://demo.bytebase.com.+This is the demo data for https://demo.bytebase.com.`dump.sql` itself is dumped from the meta database and holds schema and data for the demo.diff --git a/backend/resources/postgres/sample/0001##schema.sql b/backend/resources/postgres/sample/0001##schema.sqlindex 6c8cc28928..abf42b7afd 100644--- a/backend/resources/postgres/sample/0001##schema.sql+++ b/backend/resources/postgres/sample/0001##schema.sql@@ -3,7 +3,8 @@ DROP TABLE IF EXISTS dept_emp,title,salary,employee,- department CASCADE;+ department,+ audit CASCADE;CREATE TABLE employee (emp_no SERIAL NOT NULL,@@ -15,6 +16,8 @@ CREATE TABLE employee (PRIMARY KEY (emp_no));+CREATE INDEX idx_employee_hire_date ON employee (hire_date);+CREATE TABLE department (dept_no TEXT NOT NULL,dept_name TEXT NOT NULL,@@ -60,6 +63,45 @@ CREATE TABLE salary (PRIMARY KEY (emp_no, from_date));+CREATE INDEX idx_salary_amount ON salary (amount);++CREATE TABLE audit (+ id SERIAL PRIMARY KEY,+ operation TEXT NOT NULL,+ query TEXT,+ user_name TEXT NOT NULL,+ changed_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP+);++CREATE INDEX idx_audit_operation ON audit (operation);+CREATE INDEX idx_audit_username ON audit (user_name);+CREATE INDEX idx_audit_changed_at ON audit (changed_at);++CREATE OR REPLACE FUNCTION log_dml_operations() RETURNS TRIGGER AS $$+BEGIN+ IF (TG_OP = 'INSERT') THEN+ INSERT INTO audit (operation, query, user_name)+ VALUES ('INSERT', current_query(), current_user);+ RETURN NEW;+ ELSIF (TG_OP = 'UPDATE') THEN+ INSERT INTO audit (operation, query, user_name)+ VALUES ('UPDATE', current_query(), current_user);+ RETURN NEW;+ ELSIF (TG_OP = 'DELETE') THEN+ INSERT INTO audit (operation, query, user_name)+ VALUES ('DELETE', current_query(), current_user);+ RETURN OLD;+ END IF;+ RETURN NULL;+END;+$$ LANGUAGE plpgsql;++-- only log update and delete, otherwise, it will cause too much change.+CREATE TRIGGER salary_log_trigger+AFTER UPDATE OR DELETE ON salary+FOR EACH ROW+EXECUTE FUNCTION log_dml_operations();+CREATE OR REPLACE VIEW dept_emp_latest_date ASSELECTemp_no,