# Copyright (C) 2022 Jake Gordon, <jacob.gordon@duke.edu>
#
#    This file is part of Babase.
#
#    Babase is free software; you can redistribute it and/or modify it
#    under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Babase.  If not, see <http://www.gnu.org/licenses/>.
#
# Read the file at ./all_comments.txt, which contains a list of
# objects and the "comment" the object should have in the DB.  Ignore
# the comments, and instead write SQL that will set the comment to
# NULL for all objects listed in that file.  Print all output so we
# can use it in stdout.
#
# The list includes comments on views, so if performed as part of a
# "destroy everything" type script, run this before destroying views.
#

def writeComment(object_type, object_name):
    '''Print an SQL "COMMENT ... IS NULL" statement'''
    print ('''COMMENT ON {0} {1} IS NULL;
'''.format(object_type, object_name))

print ("""-- Copyright (C) 2022 Jake Gordon, <jacob.gordon@duke.edu>
--
--    This file is part of Babase.
--
--    Babase is free software; you can redistribute it and/or modify
--    it under the terms of the GNU General Public License as published by
--    the Free Software Foundation; either version 3 of the License, or
--    (at your option) any later version.
--
--    This program is distributed in the hope that it will be useful,
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--    GNU General Public License for more details.
--
--    You should have received a copy of the GNU General Public License
--    along with Babase.  If not, see <http://www.gnu.org/licenses/>.
--

-- DO NOT EDIT THIS FILE.  It was automatically generated.  Edit the
-- makecomments.py or all_comments.txt file instead.  (This file
-- _should_ be re-created by typing 'make' at the command line.)
""")


# Open the file
commentsFile = open("./all_comments.txt", "r")
line = commentsFile.readline() # Skip header
line = commentsFile.readline()
while line:
    thisLine = line.strip().split("\t")
    writeComment(thisLine[0], thisLine[1])
    line = commentsFile.readline()

commentsFile.close()

print()
