Skip to content

Commit dc7f34a

Browse files
committed
RHINENG-21445: drop inventory schema
1 parent af1ab61 commit dc7f34a

6 files changed

Lines changed: 93 additions & 4 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CREATE SCHEMA IF NOT EXISTS inventory;
2+
3+
-- The admin ROLE that allows the inventory schema to be managed
4+
DO $$
5+
BEGIN
6+
CREATE ROLE cyndi_admin;
7+
EXCEPTION WHEN DUPLICATE_OBJECT THEN
8+
RAISE NOTICE 'cyndi_admin already exists';
9+
END
10+
$$;
11+
GRANT ALL PRIVILEGES ON SCHEMA inventory TO cyndi_admin;
12+
13+
-- The reader ROLE that provides SELECT access to the inventory.hosts view
14+
DO $$
15+
BEGIN
16+
CREATE ROLE cyndi_reader;
17+
EXCEPTION WHEN DUPLICATE_OBJECT THEN
18+
RAISE NOTICE 'cyndi_reader already exists';
19+
END
20+
$$;
21+
GRANT USAGE ON SCHEMA inventory TO cyndi_reader;
22+
23+
-- The application user is granted the reader role only to eliminate any interference with Cyndi
24+
GRANT cyndi_reader to listener;
25+
GRANT cyndi_reader to evaluator;
26+
GRANT cyndi_reader to manager;
27+
GRANT cyndi_reader TO vmaas_sync;
28+
29+
GRANT cyndi_admin to cyndi;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
DO $$
2+
BEGIN
3+
REVOKE cyndi_reader FROM listener;
4+
EXCEPTION WHEN undefined_object THEN NULL;
5+
END
6+
$$;
7+
8+
DO $$
9+
BEGIN
10+
REVOKE cyndi_reader FROM evaluator;
11+
EXCEPTION WHEN undefined_object THEN NULL;
12+
END
13+
$$;
14+
15+
DO $$
16+
BEGIN
17+
REVOKE cyndi_reader FROM manager;
18+
EXCEPTION WHEN undefined_object THEN NULL;
19+
END
20+
$$;
21+
22+
DO $$
23+
BEGIN
24+
REVOKE cyndi_reader FROM vmaas_sync;
25+
EXCEPTION WHEN undefined_object THEN NULL;
26+
END
27+
$$;
28+
29+
DO $$
30+
BEGIN
31+
REVOKE cyndi_admin FROM cyndi;
32+
EXCEPTION WHEN undefined_object THEN NULL;
33+
END
34+
$$;
35+
36+
DO $$
37+
BEGIN
38+
IF EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = 'inventory') THEN
39+
EXECUTE 'REVOKE ALL PRIVILEGES ON SCHEMA inventory FROM cyndi_admin';
40+
END IF;
41+
END
42+
$$;
43+
44+
DO $$
45+
BEGIN
46+
IF EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = 'inventory') THEN
47+
EXECUTE 'REVOKE USAGE ON SCHEMA inventory FROM cyndi_reader';
48+
END IF;
49+
END
50+
$$;
51+
52+
DROP ROLE IF EXISTS cyndi_admin;
53+
54+
DROP ROLE IF EXISTS cyndi_reader;
55+
56+
DROP SCHEMA IF EXISTS inventory CASCADE;
57+
58+
DROP USER IF EXISTS cyndi;

database_admin/schema/create_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations
77

88

99
INSERT INTO schema_migrations
10-
VALUES (147, false);
10+
VALUES (148, false);
1111

1212
-- ---------------------------------------------------------------------------
1313
-- Functions

database_admin/schema/create_users.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $$
55
BEGIN
66
FOR usr IN
77
SELECT name
8-
FROM (VALUES ('evaluator'), ('listener'), ('manager'), ('vmaas_sync'), ('cyndi')) users (name)
8+
FROM (VALUES ('evaluator'), ('listener'), ('manager'), ('vmaas_sync')) users (name)
99
WHERE name NOT IN (SELECT rolname FROM pg_catalog.pg_roles)
1010
LOOP
1111
execute 'CREATE USER ' || usr || ';';

dev/create_inventory_hosts.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ CREATE OR REPLACE VIEW inventory.hosts AS SELECT
3636
org_id,
3737
groups
3838
FROM inventory.hosts_v1_0;
39+
40+
CREATE USER cyndi;

tasks/vmaas_sync/metrics_db_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func TestTableSizes(t *testing.T) {
1717
for _, item := range tableSizes {
1818
uniqueTables[item.Key] = true
1919
}
20-
assert.Equal(t, 231, len(tableSizes))
21-
assert.Equal(t, 231, len(uniqueTables))
20+
assert.Equal(t, 230, len(tableSizes))
21+
assert.Equal(t, 230, len(uniqueTables))
2222
assert.True(t, uniqueTables["public.system_inventory"]) // check whether table names were loaded
2323
assert.True(t, uniqueTables["public.system_patch"]) // check whether table names were loaded
2424
assert.True(t, uniqueTables["public.package"])

0 commit comments

Comments
 (0)