Skip to content

Commit e74f10c

Browse files
gordthompsonrafiss
authored andcommitted
Make further improvements to reflection
- get_multi_indexes - get_multi_pk_constraint - get_multi_check_constraints - get_table_comment (via fix in SQLA 2.0.36) Also, - unskip several tests - update requirements
1 parent 2a96a25 commit e74f10c

File tree

7 files changed

+184
-153
lines changed

7 files changed

+184
-153
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Unreleased
33

44
- Add support for READ COMMITTED transaction isolation
55
(see [README.read_committed.md](README.read_committed.md))
6+
- Add column comment to get_columns method (#253), thanks to @dotan-mor
7+
- Fix autogenerate with ON UPDATE / DELETE (#258), thanks to @idumitrescu-dn
8+
- Improve support for table/column comments (via SQLA 2.0.36)
69

710

811
# Version 2.0.2

dev-requirements.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ certifi==2024.8.30
44
# via requests
55
cffi==1.17.1
66
# via cryptography
7-
charset-normalizer==3.3.2
7+
charset-normalizer==3.4.0
88
# via requests
99
cryptography==43.0.1
1010
# via secretstorage
11-
distlib==0.3.8
11+
distlib==0.3.9
1212
# via virtualenv
1313
docutils==0.21.2
1414
# via readme-renderer
15-
filelock==3.16.0
15+
filelock==3.16.1
1616
# via
1717
# tox
1818
# virtualenv
@@ -26,13 +26,13 @@ jaraco-classes==3.4.0
2626
# via keyring
2727
jaraco-context==6.0.1
2828
# via keyring
29-
jaraco-functools==4.0.2
29+
jaraco-functools==4.1.0
3030
# via keyring
3131
jeepney==0.8.0
3232
# via
3333
# keyring
3434
# secretstorage
35-
keyring==25.3.0
35+
keyring==25.4.1
3636
# via twine
3737
markdown-it-py==3.0.0
3838
# via rich
@@ -48,7 +48,7 @@ packaging==24.1
4848
# via tox
4949
pkginfo==1.10.0
5050
# via twine
51-
platformdirs==4.3.3
51+
platformdirs==4.3.6
5252
# via virtualenv
5353
pluggy==1.5.0
5454
# via tox
@@ -70,7 +70,7 @@ requests-toolbelt==1.0.0
7070
# via twine
7171
rfc3986==2.0.0
7272
# via twine
73-
rich==13.8.1
73+
rich==13.9.2
7474
# via twine
7575
secretstorage==3.3.3
7676
# via keyring
@@ -82,11 +82,13 @@ tox==3.23.1
8282
# via -r dev-requirements.in
8383
twine==5.1.1
8484
# via -r dev-requirements.in
85+
typing-extensions==4.12.2
86+
# via rich
8587
urllib3==2.2.3
8688
# via
8789
# requests
8890
# twine
89-
virtualenv==20.26.4
91+
virtualenv==20.26.6
9092
# via tox
9193
zipp==3.20.2
9294
# via importlib-metadata

sqlalchemy_cockroachdb/base.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,22 @@ def get_indexes(self, conn, table_name, schema=None, **kw):
340340
)
341341
return result
342342

343+
def get_multi_indexes(
344+
self, connection, schema, filter_names, scope, kind, **kw
345+
):
346+
result = super().get_multi_indexes(
347+
connection, schema, filter_names, scope, kind, **kw
348+
)
349+
if schema is None:
350+
result = dict(result)
351+
for k in [
352+
(None, "spatial_ref_sys"),
353+
(None, "geometry_columns"),
354+
(None, "geography_columns"),
355+
]:
356+
result.pop(k, None)
357+
return result
358+
343359
def get_foreign_keys_v1(self, conn, table_name, schema=None, **kw):
344360
fkeys = []
345361
FK_REGEX = re.compile(r"(?P<referred_table>.+)?\.\[(?P<referred_columns>.+)?]")
@@ -506,6 +522,20 @@ def get_pk_constraint(self, conn, table_name, schema=None, **kw):
506522
res["name"] = pk["name"]
507523
return res
508524

525+
def get_multi_pk_constraint(self, connection, schema, filter_names, scope, kind, **kw):
526+
result = super().get_multi_pk_constraint(
527+
connection, schema, filter_names, scope, kind, **kw
528+
)
529+
if schema is None:
530+
result = dict(result)
531+
for k in [
532+
(None, "spatial_ref_sys"),
533+
(None, "geometry_columns"),
534+
(None, "geography_columns"),
535+
]:
536+
result.pop(k, None)
537+
return result
538+
509539
def get_unique_constraints(self, conn, table_name, schema=None, **kw):
510540
if self._is_v21plus:
511541
return super().get_unique_constraints(conn, table_name, schema, **kw)
@@ -524,13 +554,21 @@ def get_unique_constraints(self, conn, table_name, schema=None, **kw):
524554
res.append(index)
525555
return res
526556

527-
def get_check_constraints(self, conn, table_name, schema=None, **kw):
528-
if self._is_v21plus:
529-
return super().get_check_constraints(conn, table_name, schema, **kw)
530-
# TODO(bdarnell): The postgres dialect implementation depends on
531-
# pg_table_is_visible, which is supported in cockroachdb 1.1
532-
# but not in 1.0. Figure out a versioning strategy.
533-
return []
557+
def get_multi_check_constraints(
558+
self, connection, schema, filter_names, scope, kind, **kw
559+
):
560+
result = super().get_multi_check_constraints(
561+
connection, schema, filter_names, scope, kind, **kw
562+
)
563+
if schema is None:
564+
result = dict(result)
565+
for k in [
566+
(None, "spatial_ref_sys"),
567+
(None, "geometry_columns"),
568+
(None, "geography_columns"),
569+
]:
570+
result.pop(k, None)
571+
return result
534572

535573
def do_savepoint(self, connection, name):
536574
# Savepoint logic customized to work with run_transaction().

test-requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
alembic==1.13.2
1+
alembic==1.13.3
22
# via -r test-requirements.in
33
async-timeout==4.0.3
44
# via asyncpg
@@ -8,13 +8,13 @@ attrs==24.2.0
88
# via pytest
99
futures==3.0.5
1010
# via -r test-requirements.in
11-
greenlet==3.1.0
11+
greenlet==3.1.1
1212
# via sqlalchemy
1313
iniconfig==2.0.0
1414
# via pytest
1515
mako==1.3.5
1616
# via alembic
17-
markupsafe==2.1.5
17+
markupsafe==3.0.1
1818
# via mako
1919
mock==5.1.0
2020
# via -r test-requirements.in
@@ -24,19 +24,19 @@ packaging==24.1
2424
# via pytest
2525
pluggy==1.5.0
2626
# via pytest
27-
psycopg==3.2.2
27+
psycopg==3.2.3
2828
# via -r test-requirements.in
2929
psycopg2==2.9.9
3030
# via -r test-requirements.in
3131
py==1.11.0
3232
# via pytest
3333
pytest==7.1.3
3434
# via -r test-requirements.in
35-
sqlalchemy==2.0.35
35+
sqlalchemy==2.0.36
3636
# via
3737
# -r test-requirements.in
3838
# alembic
39-
tomli==2.0.1
39+
tomli==2.0.2
4040
# via pytest
4141
typing-extensions==4.12.2
4242
# via

test/test_across_schema.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ def test_get_columns_indexes_across_schema(self):
3737
Table("users", self.meta, autoload_with=testing.db, schema="public")
3838
Table("columns", self.meta, autoload_with=testing.db, schema="information_schema")
3939

40-
def test_returning_clause(self):
41-
if not testing.db.dialect._is_v2plus:
42-
return
43-
44-
# TODO(bdarnell): remove this when cockroachdb/cockroach#17008 is fixed.
45-
# across schema returning is schema.table.id but cockroachdb not support.
46-
table = Table("users", self.meta, autoload_with=testing.db, schema="public")
47-
with testing.db.begin() as conn:
48-
conn.execute(table.insert().values(dict(name="John")).returning(table.c.name))
49-
5040
def test_using_info_schema(self):
5141
if not testing.db.dialect._is_v2plus:
5242
return

test/test_suite_alembic.py

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,7 @@
11
from alembic.testing.suite import * # noqa
22
from sqlalchemy.testing import skip
3-
from alembic.testing.suite import AutogenerateCommentsTest as _AutogenerateCommentsTest
4-
from alembic.testing.suite import AutogenerateComputedTest as _AutogenerateComputedTest
53
from alembic.testing.suite import AutogenerateFKOptionsTest as _AutogenerateFKOptionsTest
6-
from alembic.testing.suite import AutogenerateForeignKeysTest as _AutogenerateForeignKeysTest
74
from alembic.testing.suite import BackendAlterColumnTest as _BackendAlterColumnTest
8-
from alembic.testing.suite import IncludeHooksTest as _IncludeHooksTest
9-
10-
11-
class AutogenerateCommentsTest(_AutogenerateCommentsTest):
12-
@skip("cockroachdb")
13-
def test_add_column_comment(self):
14-
pass
15-
16-
@skip("cockroachdb")
17-
def test_add_table_comment(self):
18-
pass
19-
20-
@skip("cockroachdb")
21-
def test_alter_column_comment(self):
22-
pass
23-
24-
@skip("cockroachdb")
25-
def test_alter_table_comment(self):
26-
pass
27-
28-
@skip("cockroachdb")
29-
def test_existing_column_comment_no_change(self):
30-
pass
31-
32-
@skip("cockroachdb")
33-
def test_existing_table_comment_no_change(self):
34-
pass
35-
36-
@skip("cockroachdb")
37-
def test_remove_column_comment(self):
38-
pass
39-
40-
@skip("cockroachdb")
41-
def test_remove_table_comment(self):
42-
pass
43-
44-
45-
class AutogenerateComputedTest(_AutogenerateComputedTest):
46-
@skip("cockroachdb")
47-
def test_add_computed_column(self):
48-
pass
49-
50-
@skip("cockroachdb")
51-
def test_cant_change_computed_warning(self):
52-
pass
53-
54-
@skip("cockroachdb")
55-
def test_computed_unchanged(self):
56-
pass
57-
58-
@skip("cockroachdb")
59-
def test_remove_computed_column(self):
60-
pass
615

626

637
class AutogenerateFKOptionsTest(_AutogenerateFKOptionsTest):
@@ -66,44 +10,6 @@ def test_nochange_ondelete(self):
6610
pass
6711

6812

69-
class AutogenerateForeignKeysTest(_AutogenerateForeignKeysTest):
70-
@skip("cockroachdb")
71-
def test_add_composite_fk_with_name(self):
72-
pass
73-
74-
@skip("cockroachdb")
75-
def test_add_fk(self):
76-
pass
77-
78-
@skip("cockroachdb")
79-
def test_add_fk_colkeys(self):
80-
pass
81-
82-
@skip("cockroachdb")
83-
def test_casing_convention_changed_so_put_drops_first(self):
84-
pass
85-
86-
@skip("cockroachdb")
87-
def test_no_change(self):
88-
pass
89-
90-
@skip("cockroachdb")
91-
def test_no_change_colkeys(self):
92-
pass
93-
94-
@skip("cockroachdb")
95-
def test_no_change_composite_fk(self):
96-
pass
97-
98-
@skip("cockroachdb")
99-
def test_remove_composite_fk(self):
100-
pass
101-
102-
@skip("cockroachdb")
103-
def test_remove_fk(self):
104-
pass
105-
106-
10713
class BackendAlterColumnTest(_BackendAlterColumnTest):
10814
@skip("cockroachdb")
10915
def test_modify_nullable_to_non(self):
@@ -115,17 +21,3 @@ def test_modify_nullable_to_non(self):
11521
def test_modify_type_int_str(self):
11622
# TODO: enable this test when warning removed for ALTER COLUMN int → string
11723
pass
118-
119-
120-
class IncludeHooksTest(_IncludeHooksTest):
121-
@skip("cockroachdb")
122-
def test_add_metadata_fk(self):
123-
pass
124-
125-
@skip("cockroachdb")
126-
def test_change_fk(self):
127-
pass
128-
129-
@skip("cockroachdb")
130-
def test_remove_connection_fk(self):
131-
pass

0 commit comments

Comments
 (0)