blob: 897cb86d4c3923c131164fb451ad7ea5027b1f38 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Presubmit script just for Monorail's SQL files."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10
11def AlterTableCheck(input_api, output_api): # pragma: no cover
12 this_dir = input_api.PresubmitLocalPath()
13 sql_files = set(x for x in input_api.os_listdir(this_dir)
14 if (x.endswith('.sql') and x != 'queries.sql'))
15 log_file = input_api.os_path.join(this_dir, 'alter-table-log.txt')
16 affected_files = set(f.LocalPath() for f in input_api.AffectedTextFiles())
17
18 if (any(f in affected_files for f in sql_files) ^
19 (log_file in affected_files)):
20 return [output_api.PresubmitPromptOrNotify(
21 'It looks like you have modified the sql schema without updating\n'
22 'the alter-table-log, or vice versa. Are you sure you want to do this?')
23 ]
24 return []
25
26
27def CheckChangeOnUpload(input_api, output_api): # pragma: no cover
28 output = AlterTableCheck(input_api, output_api)
29 return output
30
31
32def CheckChangeOnCommit(input_api, output_api): # pragma: no cover
33 output = AlterTableCheck(input_api, output_api)
34 return output