cockroachdb / cockroachdb/sqlalchemy-cockroachdb

get_columns() does not reflect Identity columns

未關閉
#297 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
156
分支
65
PR 合併指標
30 天內沒有已合併 PR

描述

CockroachDB supports `GENERATED ALWAYS AS IDENTITY` columns, and `information_schema.columns` correctly reports `is_identity = 'YES'` and `identity_generation = 'ALWAYS'` for these columns.

However, the dialect's `get_columns()` does not include identity information in the returned column dict. It returns `default: nextval('..._seq')` but `identity` is absent from the result.

This causes Alembic autogenerate to emit a spurious `AlterColumnOp` on every run for any Identity column — it sees `Identity(always=True)` in the model but no Identity in the reflected column, and tries to add it.

## Reproduction

```python
from sqlalchemy import create_engine, inspect, text

engine = create_engine("cockroachdb://...")

# Create a table with an Identity column
with engine.begin() as conn:
conn.execute(text("CREATE TABLE IF NOT EXISTS identity_test (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY)"))

# Reflect it
inspector = inspect(engine)
cols = inspector.get_columns("identity_test")
for col in cols:
print(col)
# Expected: {..., 'identity': {'always': True, ...}, ...}
# Actual: {'name': 'id', 'type': INTEGER(), 'nullable': False, 'default': "nextval('public.identity_test_id_seq'::REGCLASS)", 'autoincrement': True, ...}
# 'identity' key is absent

# Cleanup
with engine.begin() as conn:
conn.execute(text("DROP TABLE IF EXISTS identity_test"))
```

**Expected:** The `identity` key should be populated when the column uses `GENERATED ALWAYS AS IDENTITY`.

**Actual:** The `identity` key is absent. The underlying sequence is reported as a plain `default`.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。