-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_formatted_sql.py
64 lines (55 loc) · 1.21 KB
/
test_formatted_sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
###
### This script ensures that "--liquibase formatted sql" is included
###
### Notes:
###
### Helpers come from Liquibase
###
import os
import sys
import liquibase_utilities
import liquibase_changesets
###
### Retrieve log handler
### Ex. liquibase_logger.info(message)
###
liquibase_logger = liquibase_utilities.get_logger()
###
### Retrieve status handler
###
liquibase_status = liquibase_utilities.get_status()
###
### Retrieve changeset
###
changeset = liquibase_utilities.get_changeset()
###
### Retrieve changeset file
###
filepath = changeset.getChangeLog().getPhysicalFilePath()
###
### Ignore if not sql file
###
ext = os.path.splitext(filepath)[-1].lower()
if ext != ".sql":
liquibase_logger.info(f"{ext} file extension skipped.")
liquibase_status.fired = False
sys.exit(1)
###
### Check for "formatted sql" in file
###
found = False
with open(filepath, 'r') as file:
for line in file:
line = line.strip()
if len(line) > 0:
if "--liquibase formatted sql" in line:
found = True
break
if found == False:
liquibase_status.fired = True
liquibase_status.message = "Liquibase meta data missing."
sys.exit(1)
###
### Default return code
###
False