-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathconstraints.py
39 lines (28 loc) · 1.04 KB
/
constraints.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
import json
from db import connection as db_conn
def get_constraints_for_table(table_oid, conn):
return db_conn.select_from_msar_func(conn, 'get_constraints_for_table', table_oid)
def create_constraint(table_oid, constraint_obj_list, conn):
"""
Create a constraint using a psycopg connection.
Args:
constraint_obj_list: (See __msar.process_con_def_jsonb for details)
conn: a psycopg connection
Returns:
Returns a list of oid(s) of constraints for a given table.
"""
return db_conn.exec_msar_func(
conn, 'add_constraints', table_oid, json.dumps(constraint_obj_list)
).fetchone()[0]
def drop_constraint_via_oid(table_oid, constraint_oid, conn):
"""
Drop a constraint.
Args:
table_oid: Identity of the table to delete constraint for.
constraint_oid: The OID of the constraint to delete.
Returns:
The name of the dropped constraint.
"""
return db_conn.exec_msar_func(
conn, 'drop_constraint', table_oid, constraint_oid
).fetchone()[0]