Jcrespo has submitted this change and it was merged.

Change subject: mariadb: change check_private_data to print DROP statements
......................................................................


mariadb: change check_private_data to print DROP statements

To ease it usage, check_private_data.py now prints DROP DATABASE,
DROP TABLE and commented UPDATE statements when marking unfiltered
data.

Bug: T147052
Change-Id: I7204d3ccbd5711bb14d58c9d214b992260e0e848
---
M modules/role/files/mariadb/check_private_data.py
1 file changed, 34 insertions(+), 6 deletions(-)

Approvals:
  Jcrespo: Looks good to me, approved
  Marostegui: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/modules/role/files/mariadb/check_private_data.py 
b/modules/role/files/mariadb/check_private_data.py
index df4cac5..dc03abb 100644
--- a/modules/role/files/mariadb/check_private_data.py
+++ b/modules/role/files/mariadb/check_private_data.py
@@ -151,6 +151,33 @@
     return unfiltered_columns
 
 
+def drop_databases(dbs):
+    """
+    Prints an SQL drop database statement for each of the database given on
+    the list
+    """
+    for db in dbs:
+        print("DROP DATABASE `{}`".format(db))
+
+
+def drop_tables(tables):
+    """
+    Prints a drop table statement for each of the database given on the list
+    """
+    for table in tables:
+        print("DROP TABLE `{}`.{}`".format(table[0], table[1]))
+
+
+def update_columns(cols):
+    """
+    prints a commented update statement for each of the columns given
+    on the list
+    """
+    for col in cols:
+        print(("-- UPDATE `{}`.{}`"
+               "   SET `{}` = NULL").format(col[0], col[1], col[2]))
+
+
 def main():
     (private_dblist, private_tables, filtered_tables, public_wiki_dbs,
      public_view_dbs, public_dbs) = get_lists(all_dblist_path,
@@ -160,21 +187,22 @@
     db = pymysql.connect(host='localhost', user='root',
                          unix_socket='/tmp/mysql.sock')
 
-    print('Non-public databases that are present:')
+    print('-- Non-public databases that are present:')
     private_databases_present = get_private_databases(db, public_dbs,
                                                       public_view_dbs,
                                                       SYSTEM_DBS,
                                                       USER_DATABASES_REGEX)
-    print(private_databases_present)
+    drop_databases(private_databases_present)
 
-    print('Non-public tables that are present:')
+    print('-- Non-public tables that are present:')
     private_tables_present = get_private_tables(db, private_tables, SYSTEM_DBS,
                                                 USER_DATABASES_REGEX)
-    print(private_tables_present)
-    print('Unfiltered columns that are present:')
+    drop_tables(private_tables_present)
+
+    print('-- Unfiltered columns that are present:')
     unfiltered_columns_present = get_unfiltered_columns(db, filtered_tables,
                                                         public_wiki_dbs)
-    print(unfiltered_columns_present)
+    update_columns(unfiltered_columns_present)
 
 
 if __name__ == "__main__":

-- 
To view, visit https://gerrit.wikimedia.org/r/324386
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7204d3ccbd5711bb14d58c9d214b992260e0e848
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Marostegui <maroste...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to