Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add testing schema for mysql and pg
天舟2c71e1c0c7ea
diff --git a/store/test_schema/README.md b/store/test_schema/README.mdnew file mode 100644index 0000000000..577a4aa89b--- /dev/null+++ b/store/test_schema/README.md@@ -0,0 +1 @@+This folder stores various test schemas for each database enginediff --git a/store/test_schema/mysql/1_todo.sql b/store/test_schema/mysql/1_todo.sqlnew file mode 100644index 0000000000..b925a47d9c--- /dev/null+++ b/store/test_schema/mysql/1_todo.sql@@ -0,0 +1,23 @@+-- Covered objects:+-- - Table+-- - Index++CREATE DATABASE bytebase_test_todo;++-- Table and Index+CREATE TABLE bytebase_test_todo.author (+ id INTEGER PRIMARY KEY AUTO_INCREMENT,+ name VARCHAR(255) COMMENT 'name of the author'+);++CREATE TABLE bytebase_test_todo.todo (+ id INTEGER PRIMARY KEY AUTO_INCREMENT,+ name VARCHAR(255) COMMENT 'name of the todo',+ content TEXT,+ author_id INTEGER,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,+ INDEX (name) COMMENT 'index on todo.name',+ INDEX (created_ts) COMMENT 'index on todo.created_ts',+);\ No newline at end of filediff --git a/store/test_schema/mysql/2_blog.sql b/store/test_schema/mysql/2_blog.sqlnew file mode 100644index 0000000000..42721b6dbe--- /dev/null+++ b/store/test_schema/mysql/2_blog.sql@@ -0,0 +1,98 @@+-- Covered objects:+-- - Table+-- - Index+-- - View+-- - Procedure+-- - Function+-- - Event+-- - Trigger++CREATE DATABASE bytebase_test_blog;++-- Table and Index+CREATE TABLE bytebase_test_blog.author (+ id INTEGER PRIMARY KEY AUTO_INCREMENT,+ name VARCHAR(255) COMMENT 'name of the author',+ email VARCHAR(255),+ coin INTEGER DEFAULT 0 COMMENT 'coin can be earned by posting posts, comments'+);++CREATE TABLE bytebase_test_blog.post (+ id INTEGER PRIMARY KEY AUTO_INCREMENT,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ author_id INTEGER NOT NULL,+ name VARCHAR(255) COMMENT 'name of the post',+ content TEXT,+ like_count INTEGER DEFAULT 0,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,+ INDEX (name),+ INDEX (created_ts)+);++CREATE TABLE bytebase_test_blog.comment (+ id INTEGER PRIMARY KEY AUTO_INCREMENT,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ post_id INTEGER,+ author_id INTEGER,+ content TEXT,+ FOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,+ INDEX (created_ts)+);++-- View+CREATE VIEW bytebase_test_blog.top_like_post AS+SELECT+ *+FROM+ bytebase_test_blog.post+ORDER BY+ like_count DESC+LIMIT 10;++-- Procedure+CREATE PROCEDURE bytebase_test_blog.author_post_count (IN author_id INT, OUT post_count INT)+BEGIN+ SELECT+ COUNT(*) INTO post_count+ FROM+ author, post+ WHERE+ author.id = post.author_id AND author.id = author_id;+END;++-- Function+CREATE FUNCTION bytebase_test_blog.author_comment_count (author_id INT)+ RETURNS INT DETERMINISTIC+BEGIN+DECLARE+ comment_count INT DEFAULT 0;+ SELECT+ COUNT(*) INTO comment_count+ FROM+ author,+ COMMENT+ WHERE+ author.id = comment.author_id+ AND author.id = author_id;+ RETURN comment_count;+END;++-- Event+CREATE EVENT bytebase_test_blog.increase_author_coin_daily ON SCHEDULE EVERY 1 DAY DO UPDATE author+SET coin = coin + 1;++-- Trigger+CREATE TRIGGER bytebase_test_blog.update_post_updated_ts+ AFTER UPDATE ON post+ FOR EACH ROW+BEGIN+ UPDATE+ post+ SET+ updated_ts = NOW()+ WHERE+ id = OLD.id;+END;\ No newline at end of filediff --git a/store/test_schema/pg/1_todo.sql b/store/test_schema/pg/1_todo.sqlnew file mode 100644index 0000000000..04b2fac788--- /dev/null+++ b/store/test_schema/pg/1_todo.sql@@ -0,0 +1,31 @@+-- Covered objects:+-- - Sequence+-- - Table+-- - Index++CREATE DATABASE bytebase_test_todo;++-- Reconnect to bytebase_test_todo before running following sql+-- Sequence, Table and Index+CREATE TABLE public.author (+ id SERIAL PRIMARY KEY,+ name VARCHAR(255)+);++COMMENT ON COLUMN public.author.name is 'name of the author';++CREATE TABLE public.todo (+ id SERIAL PRIMARY KEY,+ name VARCHAR(255) COMMENT 'name of the todo',+ content TEXT,+ author_id INTEGER,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE+);++CREATE INDEX bytebase_test_todo_todo_name ON public.todo(name);+CREATE INDEX bytebase_test_todo_todo_created_ts ON public.todo(created_ts);++COMMENT ON INDEX bytebase_test_todo_todo_name is 'index on todo.name';+COMMENT ON INDEX bytebase_test_todo_todo_created_ts is 'index on todo.created_ts';\ No newline at end of filediff --git a/store/test_schema/pg/2_blog.sql b/store/test_schema/pg/2_blog.sqlnew file mode 100644index 0000000000..0b806ad028--- /dev/null+++ b/store/test_schema/pg/2_blog.sql@@ -0,0 +1,112 @@+-- Covered objects:+-- - Sequence+-- - Table+-- - Index+-- - View+-- - Procedure+-- - Function+-- - Trigger+-- - Event Trigger++CREATE DATABASE bytebase_test_blog;++-- Reconnect to bytebase_test_todo before running following sql+-- Sequence, Table and Index+CREATE TABLE public.author (+ id SERIAL PRIMARY KEY,+ name VARCHAR(255),+ email VARCHAR(255),+ coin INTEGER DEFAULT 0+);++COMMENT ON COLUMN public.author.coin is 'coin can be earned by posting posts, comments';++CREATE TABLE public.post (+ id SERIAL PRIMARY KEY,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ author_id INTEGER NOT NULL,+ name VARCHAR(255),+ content TEXT,+ like_count INTEGER DEFAULT 0,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE+);++CREATE INDEX bytebase_test_blog_post_name ON public.post(name);+CREATE INDEX bytebase_test_blog_post_created_ts ON public.post(created_ts);++COMMENT ON COLUMN public.post.name is 'name of the post';++CREATE TABLE public.comment (+ id SERIAL PRIMARY KEY,+ created_ts BIGINT NOT NULL,+ updated_ts BIGINT NOT NULL,+ post_id INTEGER,+ author_id INTEGER,+ content TEXT,+ FOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,+ FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE+);++CREATE INDEX bytebase_test_blog_comment_created_ts ON public.comment(created_ts);++-- View+CREATE VIEW public.top_like_post AS+SELECT+ *+FROM+ public.post+ORDER BY+ like_count DESC+LIMIT 10;++-- Procedure+CREATE PROCEDURE public.add_coin (author_id INT, count INT)+LANGUAGE SQL+AS $$+ UPDATE+ author SET+ coin = coin + count+ WHERE+ author.id = author_id;+$$;++-- Function+CREATE FUNCTION public.author_post_count (author_id INT)+ RETURNS BIGINT+ AS 'SELECT+ COUNT(*)+ FROM+ author, post+ WHERE+ author.id = post.author_id AND author.id = author_id;'+ LANGUAGE SQL+ IMMUTABLE+ RETURNS NULL ON NULL INPUT;++-- Trigger+CREATE OR REPLACE FUNCTION update_updated_ts()+RETURNS TRIGGER AS $$+BEGIN+ NEW.updated_ts = now();+ RETURN NEW;+END;+$$ language 'plpgsql';++CREATE TRIGGER update_post_updated_ts+ BEFORE UPDATE ON post+ FOR EACH ROW+ EXECUTE PROCEDURE update_updated_ts ();++-- Event Trigger+CREATE OR REPLACE FUNCTION abort_any_command()+ RETURNS event_trigger+ LANGUAGE plpgsql+ AS $$+BEGIN+ RAISE EXCEPTION 'command % is disabled', tg_tag;+END;+$$;++CREATE EVENT TRIGGER abort_drop ON sql_drop+ EXECUTE FUNCTION abort_any_command();\ No newline at end of file