Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit fe16957

Browse files
committed
Added Database.SUPPORTS_UNIQUE_CONSTAINT
1 parent f5d155b commit fe16957

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

data_diff/databases/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Database(AbstractDatabase):
110110
default_schema: str = None
111111
SUPPORTS_ALPHANUMS = True
112112
SUPPORTS_PRIMARY_KEY = False
113+
SUPPORTS_UNIQUE_CONSTAINT = False
113114

114115
_interactive = False
115116

@@ -245,6 +246,8 @@ def select_table_unique_columns(self, path: DbPath) -> str:
245246
)
246247

247248
def query_table_unique_columns(self, path: DbPath) -> List[str]:
249+
if not self.SUPPORTS_UNIQUE_CONSTAINT:
250+
raise NotImplementedError("This database doesn't support 'unique' constraints")
248251
res = self.query(self.select_table_unique_columns(path), List[str])
249252
return list(res)
250253

data_diff/databases/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class MySQL(ThreadedDatabase):
4040
ROUNDS_ON_PREC_LOSS = True
4141
SUPPORTS_ALPHANUMS = False
4242
SUPPORTS_PRIMARY_KEY = True
43+
SUPPORTS_UNIQUE_CONSTAINT = True
4344

4445
def __init__(self, *, thread_count, **kw):
4546
self._args = kw

data_diff/databases/oracle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Oracle(ThreadedDatabase):
4040
}
4141
ROUNDS_ON_PREC_LOSS = True
4242
SUPPORTS_PRIMARY_KEY = True
43+
SUPPORTS_UNIQUE_CONSTAINT = True
4344

4445
def __init__(self, *, host, database, thread_count, **kw):
4546
self.kwargs = dict(dsn=f"{host}/{database}" if database else host, **kw)

data_diff/databases/postgresql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class PostgreSQL(ThreadedDatabase):
4747
}
4848
ROUNDS_ON_PREC_LOSS = True
4949
SUPPORTS_PRIMARY_KEY = True
50+
SUPPORTS_UNIQUE_CONSTAINT = True
5051

5152
default_schema = "public"
5253

data_diff/joindiff_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _test_duplicate_keys(self, table1: TableSegment, table2: TableSegment):
201201

202202
# Test duplicate keys
203203
for ts in [table1, table2]:
204-
unique = ts.database.query_table_unique_columns(ts.table_path)
204+
unique = ts.database.query_table_unique_columns(ts.table_path) if ts.database.SUPPORTS_UNIQUE_CONSTAINT else []
205205

206206
t = ts.make_select()
207207
key_columns = ts.key_columns

0 commit comments

Comments
 (0)