Generate ER diagrams in :nom:generate_golden_file (#867)

Generate entity relationship diagrams during the same step in which we
generate the golden schema.
This commit is contained in:
Michael Muller 2020-11-10 10:03:28 -05:00 committed by GitHub
parent 1c630cf0a9
commit c1745e4b01
2 changed files with 16 additions and 7 deletions

View file

@ -300,9 +300,15 @@ def do_pseudo_task(task: str) -> None:
f'{root}/db/src/main/resources/sql/schema/' f'{root}/db/src/main/resources/sql/schema/'
'nomulus.golden.sql') 'nomulus.golden.sql')
if subprocess.call([f'{root}/gradlew', ':db:test']): # Rerun :db:test and regenerate the ER diagram (at "warning" log
print('\033[31mERROR:\033[0m Golden file test failed after ' # level so it doesn't generate pages of messaging)
'copying schema. Please check your flyway files.') if subprocess.call([f'{root}/gradlew', ':db:test', 'devTool',
'--args=-e localhost --log_level=WARNING '
'generate_sql_er_diagram -o '
f'{root}/db/src/main/resources/sql/er_diagram']):
print('\033[31mERROR:\033[0m Golden file test or ER diagram '
'generation failed after copying schema. Please check your '
'flyway files.')
raise Abort() raise Abort()
else: else:
print(f'\033[31mERROR:\033[0m Unknown task {task}') print(f'\033[31mERROR:\033[0m Unknown task {task}')
@ -377,6 +383,7 @@ def main(args) -> int:
# See if there are any special ":nom:" pseudo-tasks specified. # See if there are any special ":nom:" pseudo-tasks specified.
got_non_pseudo_tasks = False got_non_pseudo_tasks = False
got_pseudo_tasks = False
for arg in args.non_flag_args[1:]: for arg in args.non_flag_args[1:]:
if arg.startswith(':nom:'): if arg.startswith(':nom:'):
if got_non_pseudo_tasks: if got_non_pseudo_tasks:
@ -388,13 +395,14 @@ def main(args) -> int:
'specified prior to all actual gradle tasks. Aborting.') 'specified prior to all actual gradle tasks. Aborting.')
return 1 return 1
do_pseudo_task(arg) do_pseudo_task(arg)
got_pseudo_tasks = True
else: else:
got_non_pseudo_tasks = True got_non_pseudo_tasks = True
non_flag_args = [ non_flag_args = [
arg for arg in args.non_flag_args[1:] if not arg.startswith(':nom:')] arg for arg in args.non_flag_args[1:] if not arg.startswith(':nom:')]
if not non_flag_args: if not non_flag_args:
if not got_non_pseudo_tasks: if not got_pseudo_tasks:
print('\033[33mWARNING:\033[0m No tasks specified. Not ' print('\033[33mWARNING:\033[0m No tasks specified. Not '
'doing anything') 'doing anything')
return 0 return 0

View file

@ -113,7 +113,10 @@ class MyTest(unittest.TestCase):
nom_build.main(['nom_build', ':nom:generate_golden_file']) nom_build.main(['nom_build', ':nom:generate_golden_file'])
self.call_mock.assert_has_calls([ self.call_mock.assert_has_calls([
mock.call([GRADLEW, ':db:test']), mock.call([GRADLEW, ':db:test']),
mock.call([GRADLEW, ':db:test']) mock.call([GRADLEW, ':db:test', 'devTool',
'--args=-e localhost --log_level=WARNING '
'generate_sql_er_diagram -o '
'/tmp/rootdir/db/src/main/resources/sql/er_diagram'])
]) ])
def test_generate_golden_file_nofail(self): def test_generate_golden_file_nofail(self):
@ -122,5 +125,3 @@ class MyTest(unittest.TestCase):
self.call_mock.assert_has_calls([mock.call([GRADLEW, ':db:test'])]) self.call_mock.assert_has_calls([mock.call([GRADLEW, ':db:test'])])
unittest.main() unittest.main()