Skip to content

Commit

Permalink
Update sqlalchemy docs for prefer-identity rule (#347)
Browse files Browse the repository at this point in the history
Addresses #346
This adds sqlalchemy docs for the prefer-identity rule now that `Identity` is supported as of sqlalchemy 1.4 per https://docs.sqlalchemy.org/en/20/core/defaults.html#identity-ddl
  • Loading branch information
ThomasWunderlich authored May 7, 2024
1 parent 9ac8190 commit fa0ec26
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/docs/prefer-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ create table app.users

## solution for alembic and sqlalchemy

Built-in support for rendering of `IDENTITY` is not available yet,
As of sqlalchemy 1.4, use:

```python
# models.py
import sqlalchemy as sa

class User(BaseModel):
id = sa.Column(sa.Integer, sa.Identity(), primary_key=True)
```


For sqlalchemy 1.3 or prior built-in support for rendering of `IDENTITY` is not available yet,
however the following compilation hook may be used to replace occurrences of `SERIAL` with `IDENTITY`. See the [SQLAlchemy docs for more information](https://docs.sqlalchemy.org/en/13/dialects/postgresql.html#postgresql-10-identity-columns).

```python
Expand Down

0 comments on commit fa0ec26

Please sign in to comment.