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