Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion samples/Z0DAN/zodan.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,21 @@ def verify_node_prerequisites(self, src_node_name: str, src_dsn: str, new_node_n
except Exception as e:
self.format_notice("✗", f"Database {new_db_name} does not exist on new node")
raise Exception(f"Exiting add_node: Database {new_db_name} does not exist on new node. Please create it first.")


# Check if they previously installed lolor on the destination.
# They should not have run CREATE EXTENSION lolor yet
sql = """
SELECT count(*) FROM pg_tables
WHERE schemaname = 'lolor'
"""
user_table_count = self.run_psql(new_node_dsn, sql, fetch=True, return_single=True)

if user_table_count and int(user_table_count.strip()) > 0:
self.format_notice("✗", f"Checking database {new_db_name} to ensure lolor is not installed")
raise Exception(f"Exiting add_node: Database {new_db_name} has the lolor extension installed or remaining lolor user data. The new node should not have the lolor extension installed")
else:
self.format_notice("OK:", f"Checking database {new_db_name} to ensure lolor is not installed")

# Check if database has user-created tables
sql = """
SELECT count(*) FROM pg_tables
Expand Down
17 changes: 17 additions & 0 deletions samples/Z0DAN/zodan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,23 @@ BEGIN
RAISE EXCEPTION 'Exiting add_node: Database % does not exist on new node. Please create it first.', new_db_name;
END;

-- Check if they previously installed lolor on the destination.
-- They should not have run CREATE EXTENSION yet
DECLARE
user_table_count integer;
remotesql text;
BEGIN
remotesql := 'SELECT count(*) FROM pg_tables WHERE schemaname = ''lolor''';
SELECT * FROM dblink(new_node_dsn, remotesql) AS t(count integer) INTO user_table_count;

IF user_table_count > 0 THEN
RAISE NOTICE ' [FAILED] %', rpad('Database ' || new_db_name || ' has the lolor extension installed or remaining lolor data.', 120, ' ');
RAISE EXCEPTION 'Exiting add_node: Database % has the lolor extension installed or remaining lolor user data.', new_db_name;
ELSE
RAISE NOTICE ' OK: %', rpad('Checking database ' || new_db_name || ' to ensure lolor is not installed', 120, ' ');
END IF;
END;

-- Check if database has user-created tables in user-created schemas
DECLARE
user_table_count integer;
Expand Down