Skip to content

Commit

Permalink
Add new view to fecth existing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rodo committed Dec 13, 2024
1 parent cd5ab2f commit 0652d5c
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ SCHEMA = @extschema@

include $(PGXS)

all: $(DIST) $(PGTLEOUT) $(EXTENSION).control $(UNITTESTS) $(INTETESTS) exclude.sql
all: $(DIST) $(PGTLEOUT) $(EXTENSION).control $(UNITTESTS) $(INTETESTS)

clean:
rm -f $(PGTLEOUT) $(DIST) $(UNITTESTS)
rm -f $(PGTLEOUT) $(DIST) $(UNITTESTS) exclude.sql

$(DIST): $(FILES) exclude.sql
cat sql/table.sql > $@
cat sql/management.sql >> $@
cat sql/function.sql >> $@
cat sql/function-stop.sql >> $@
cat sql/function-status.sql >> $@
cat sql/view.sql >> $@
cat exclude.sql >> $@
cat sql/start.sql >> $@
cat $@ > dist/$(EXTENSION).sql
Expand Down
56 changes: 55 additions & 1 deletion dist/pgtle.schedoc--0.0.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ CREATE VIEW @[email protected]_column_comments AS
--
--
--
--
-- schedoc_exclude_tool(tool text)
-- schedoc_exclude_tools_all()
-- schedoc_is_table_excluded(tableoid oid)
--
-- Set up the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tool(tool text)
Expand All @@ -107,6 +112,26 @@ BEGIN
END;
$EOF$;
--
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tools_all()
RETURNS text
LANGUAGE plpgsql AS
$EOF$
DECLARE
nbrows bigint;
BEGIN
--
--
--
INSERT INTO @[email protected]_table_exclusion (schema_name, table_name, tag)
SELECT schema_name, table_name, tags[0] FROM @[email protected]_table_exclusion_templates;

SELECT count(1) FROM @[email protected]_table_exclusion INTO nbrows;

RETURN format ('Inserted %s row(s) in schedoc_table_exclusion', nbrows);
END;
$EOF$;
--
-- Check if a table is present in the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_is_table_excluded(tableoid oid)
Expand Down Expand Up @@ -324,6 +349,35 @@ BEGIN
END IF;
END;
$EOF$;
DROP VIEW IF EXISTS schedoc_column_existing_comments;
CREATE OR REPLACE VIEW schedoc_column_existing_comments AS


WITH descr AS (
SELECT c.relname, d.description
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_description d ON d.objoid = c.oid
LEFT JOIN schedoc_table_exclusion e ON e.table_name = c.relname
WHERE c.relkind = 'r' AND n.nspname='public'
AND e.table_name IS NULL
AND c.relname NOT IN (

'ddl_history',
'ddl_history_column',
'ddl_history_schema',
'schedoc_column_log',
'schedoc_column_raw',
'schedoc_table_exclusion',
'schedoc_table_exclusion_templates',
'schedoc_valid',
'schedoc_valid_status')
)
SELECT relname, description, description IS NOT NULL AND description IS JSON as is_ok
FROM descr

ORDER BY relname
;
--
-- Debezium
--
Expand Down Expand Up @@ -358,7 +412,7 @@ INSERT INTO @[email protected]_table_exclusion_templates (schema_name, table_na
VALUES
('public', 'auth_group', ARRAY['django']),
('public', 'auth_group_permissions', ARRAY['django']),
('public', 'auth_permissions', ARRAY['django']),
('public', 'auth_permission', ARRAY['django']),
('public', 'auth_user', ARRAY['django']),
('public', 'auth_user_groups', ARRAY['django']),
('public', 'auth_user_user_permissions', ARRAY['django']),
Expand Down
56 changes: 55 additions & 1 deletion dist/schedoc--0.0.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ CREATE VIEW @[email protected]_column_comments AS
--
--
--
--
-- schedoc_exclude_tool(tool text)
-- schedoc_exclude_tools_all()
-- schedoc_is_table_excluded(tableoid oid)
--
-- Set up the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tool(tool text)
Expand All @@ -101,6 +106,26 @@ BEGIN
END;
$EOF$;
--
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tools_all()
RETURNS text
LANGUAGE plpgsql AS
$EOF$
DECLARE
nbrows bigint;
BEGIN
--
--
--
INSERT INTO @[email protected]_table_exclusion (schema_name, table_name, tag)
SELECT schema_name, table_name, tags[0] FROM @[email protected]_table_exclusion_templates;

SELECT count(1) FROM @[email protected]_table_exclusion INTO nbrows;

RETURN format ('Inserted %s row(s) in schedoc_table_exclusion', nbrows);
END;
$EOF$;
--
-- Check if a table is present in the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_is_table_excluded(tableoid oid)
Expand Down Expand Up @@ -318,6 +343,35 @@ BEGIN
END IF;
END;
$EOF$;
DROP VIEW IF EXISTS schedoc_column_existing_comments;
CREATE OR REPLACE VIEW schedoc_column_existing_comments AS


WITH descr AS (
SELECT c.relname, d.description
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_description d ON d.objoid = c.oid
LEFT JOIN schedoc_table_exclusion e ON e.table_name = c.relname
WHERE c.relkind = 'r' AND n.nspname='public'
AND e.table_name IS NULL
AND c.relname NOT IN (

'ddl_history',
'ddl_history_column',
'ddl_history_schema',
'schedoc_column_log',
'schedoc_column_raw',
'schedoc_table_exclusion',
'schedoc_table_exclusion_templates',
'schedoc_valid',
'schedoc_valid_status')
)
SELECT relname, description, description IS NOT NULL AND description IS JSON as is_ok
FROM descr

ORDER BY relname
;
--
-- Debezium
--
Expand Down Expand Up @@ -352,7 +406,7 @@ INSERT INTO @[email protected]_table_exclusion_templates (schema_name, table_na
VALUES
('public', 'auth_group', ARRAY['django']),
('public', 'auth_group_permissions', ARRAY['django']),
('public', 'auth_permissions', ARRAY['django']),
('public', 'auth_permission', ARRAY['django']),
('public', 'auth_user', ARRAY['django']),
('public', 'auth_user_groups', ARRAY['django']),
('public', 'auth_user_user_permissions', ARRAY['django']),
Expand Down
56 changes: 55 additions & 1 deletion dist/schedoc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ CREATE VIEW @[email protected]_column_comments AS
--
--
--
--
-- schedoc_exclude_tool(tool text)
-- schedoc_exclude_tools_all()
-- schedoc_is_table_excluded(tableoid oid)
--
-- Set up the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tool(tool text)
Expand All @@ -101,6 +106,26 @@ BEGIN
END;
$EOF$;
--
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tools_all()
RETURNS text
LANGUAGE plpgsql AS
$EOF$
DECLARE
nbrows bigint;
BEGIN
--
--
--
INSERT INTO @[email protected]_table_exclusion (schema_name, table_name, tag)
SELECT schema_name, table_name, tags[0] FROM @[email protected]_table_exclusion_templates;

SELECT count(1) FROM @[email protected]_table_exclusion INTO nbrows;

RETURN format ('Inserted %s row(s) in schedoc_table_exclusion', nbrows);
END;
$EOF$;
--
-- Check if a table is present in the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_is_table_excluded(tableoid oid)
Expand Down Expand Up @@ -318,6 +343,35 @@ BEGIN
END IF;
END;
$EOF$;
DROP VIEW IF EXISTS schedoc_column_existing_comments;
CREATE OR REPLACE VIEW schedoc_column_existing_comments AS


WITH descr AS (
SELECT c.relname, d.description
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_description d ON d.objoid = c.oid
LEFT JOIN schedoc_table_exclusion e ON e.table_name = c.relname
WHERE c.relkind = 'r' AND n.nspname='public'
AND e.table_name IS NULL
AND c.relname NOT IN (

'ddl_history',
'ddl_history_column',
'ddl_history_schema',
'schedoc_column_log',
'schedoc_column_raw',
'schedoc_table_exclusion',
'schedoc_table_exclusion_templates',
'schedoc_valid',
'schedoc_valid_status')
)
SELECT relname, description, description IS NOT NULL AND description IS JSON as is_ok
FROM descr

ORDER BY relname
;
--
-- Debezium
--
Expand Down Expand Up @@ -352,7 +406,7 @@ INSERT INTO @[email protected]_table_exclusion_templates (schema_name, table_na
VALUES
('public', 'auth_group', ARRAY['django']),
('public', 'auth_group_permissions', ARRAY['django']),
('public', 'auth_permissions', ARRAY['django']),
('public', 'auth_permission', ARRAY['django']),
('public', 'auth_user', ARRAY['django']),
('public', 'auth_user_groups', ARRAY['django']),
('public', 'auth_user_user_permissions', ARRAY['django']),
Expand Down
24 changes: 24 additions & 0 deletions sql/management.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
--
-- schedoc_exclude_tool(tool text)
-- schedoc_exclude_tools_all()
-- schedoc_is_table_excluded(tableoid oid)
--
-- Set up the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tool(tool text)
Expand All @@ -21,6 +25,26 @@ BEGIN
END;
$EOF$;
--
--
CREATE OR REPLACE FUNCTION @[email protected]_exclude_tools_all()
RETURNS text
LANGUAGE plpgsql AS
$EOF$
DECLARE
nbrows bigint;
BEGIN
--
--
--
INSERT INTO @[email protected]_table_exclusion (schema_name, table_name, tag)
SELECT schema_name, table_name, tags[0] FROM @[email protected]_table_exclusion_templates;

SELECT count(1) FROM @[email protected]_table_exclusion INTO nbrows;

RETURN format ('Inserted %s row(s) in schedoc_table_exclusion', nbrows);
END;
$EOF$;
--
-- Check if a table is present in the exclusion list
--
CREATE OR REPLACE FUNCTION @[email protected]_is_table_excluded(tableoid oid)
Expand Down
1 change: 1 addition & 0 deletions sql/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ CREATE VIEW @[email protected]_column_comments AS

--
--
--
29 changes: 29 additions & 0 deletions sql/view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DROP VIEW IF EXISTS schedoc_column_existing_comments;
CREATE OR REPLACE VIEW schedoc_column_existing_comments AS


WITH descr AS (
SELECT c.relname, d.description
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_description d ON d.objoid = c.oid
LEFT JOIN schedoc_table_exclusion e ON e.table_name = c.relname
WHERE c.relkind = 'r' AND n.nspname='public'
AND e.table_name IS NULL
AND c.relname NOT IN (

'ddl_history',
'ddl_history_column',
'ddl_history_schema',
'schedoc_column_log',
'schedoc_column_raw',
'schedoc_table_exclusion',
'schedoc_table_exclusion_templates',
'schedoc_valid',
'schedoc_valid_status')
)
SELECT relname, description, description IS NOT NULL AND description IS JSON as is_ok
FROM descr

ORDER BY relname
;
5 changes: 4 additions & 1 deletion test/sql/management_test.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ SET search_path=public,pgtap;

BEGIN;

SELECT plan(11);
SELECT plan(12);

SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_exclude_tool'::name, ARRAY['text']);
SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_exclude_tools_all'::name);

SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_is_table_excluded'::name, ARRAY['oid']);

--
-- Return False on non existing id
Expand Down
14 changes: 14 additions & 0 deletions test/sql/view_test.sql.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--
--
--
SET search_path=public,pgtap;

BEGIN;

SELECT plan(1);

SELECT has_view('public'::name, 'schedoc_column_existing_comments'::name);

SELECT finish();

ROLLBACK;
2 changes: 1 addition & 1 deletion tools_exclusion/django.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INSERT INTO @[email protected]_table_exclusion_templates (schema_name, table_na
VALUES
('public', 'auth_group', ARRAY['django']),
('public', 'auth_group_permissions', ARRAY['django']),
('public', 'auth_permissions', ARRAY['django']),
('public', 'auth_permission', ARRAY['django']),
('public', 'auth_user', ARRAY['django']),
('public', 'auth_user_groups', ARRAY['django']),
('public', 'auth_user_user_permissions', ARRAY['django']),
Expand Down

0 comments on commit 0652d5c

Please sign in to comment.