-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollection_without_validator.py
64 lines (55 loc) · 1.42 KB
/
collection_without_validator.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 checks for a validator when creating a new collection
###
###
### Helpers come from Liquibase
###
import sys
import liquibase_database
import liquibase_utilities
###
### Constants
###
NOSQL_DATABASES = ["MongoDB"]
###
### Retrieve log handler
### Ex. liquibase_logger.info(message)
###
liquibase_logger = liquibase_utilities.get_logger()
###
### Retrieve status handler
###
liquibase_status = liquibase_utilities.get_status()
###
### Check for Mongo
###
current_database = liquibase_utilities.get_database()
product_name = liquibase_database.get_short_name(current_database)
if not product_name.casefold() in map(str.casefold, NOSQL_DATABASES):
liquibase_logger.info(f"Database {product_name} ignored")
liquibase_status.fired = False
sys.exit(1)
###
### Retrieve all changes in changeset
###
changes = liquibase_utilities.get_changeset().getChanges()
###
### Loop through all changes
###
for change in changes:
###
### Retrieve sql as string, remove extra whitespace
###
raw_sql = liquibase_utilities.strip_comments(liquibase_utilities.generate_sql(change)).casefold()
raw_sql = " ".join(raw_sql.split())
###
### Look for createCollection
###
if "createcollection" in raw_sql and not "validator:" in raw_sql:
liquibase_status.fired = True
liquibase_status.message = liquibase_utilities.get_script_message()
sys.exit(1)
###
### Default return code
###
False