Skip to content

Commit

Permalink
fix: inspectdb raise KeyError 'int2' for smallint (#401)
Browse files Browse the repository at this point in the history
* fix: inspectdb raise KeyError 'int2' for smallint

* fix ci error

* no ask confirm for ci

* docs: update changelog
  • Loading branch information
waketzheng authored Dec 27, 2024
1 parent d6a51bd commit f5d7d56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ jobs:
run: poetry run pip install --upgrade "tortoise-orm>=0.23,<0.24"
- name: Install TortoiseORM develop branch
if: matrix.tortoise-orm == 'tortoisedev'
run: poetry run pip install --upgrade "git+https://github.com/tortoise/tortoise-orm"
run: |
poetry run pip uninstall -y tortoise-orm
poetry run pip install --upgrade "git+https://github.com/tortoise/tortoise-orm"
- name: CI
env:
MYSQL_PASS: root
Expand Down
24 changes: 15 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 0.8

### [0.8.2]**(Unreleased)**

#### Fixed
- fix: inspectdb raise KeyError 'int2' for smallint. ([#401])

[#401]: https://github.com/tortoise/aerich/pull/401

### [0.8.1](../../releases/tag/v0.8.1) - 2024-12-27

#### Fixed
Expand Down Expand Up @@ -29,19 +36,18 @@
[#395]: https://github.com/tortoise/aerich/pull/395
[#394]: https://github.com/tortoise/aerich/pull/394
[#393]: https://github.com/tortoise/aerich/pull/393
[#376]: https://github.com/tortoise/aerich/pull/376
[#392]: https://github.com/tortoise/aerich/pull/392
[#388]: https://github.com/tortoise/aerich/pull/388
[#386]: https://github.com/tortoise/aerich/pull/386
[#272]: https://github.com/tortoise/aerich/pull/272
[#334]: https://github.com/tortoise/aerich/pull/334
[#284]: https://github.com/tortoise/aerich/pull/284
[#286]: https://github.com/tortoise/aerich/pull/286
[#302]: https://github.com/tortoise/aerich/pull/302
[#378]: https://github.com/tortoise/aerich/pull/378
[#377]: https://github.com/tortoise/aerich/pull/377
[#271]: https://github.com/tortoise/aerich/pull/271
[#376]: https://github.com/tortoise/aerich/pull/376
[#334]: https://github.com/tortoise/aerich/pull/334
[#302]: https://github.com/tortoise/aerich/pull/302
[#286]: https://github.com/tortoise/aerich/pull/286
[#388]: https://github.com/tortoise/aerich/pull/388
[#392]: https://github.com/tortoise/aerich/pull/392
[#284]: https://github.com/tortoise/aerich/pull/284
[#272]: https://github.com/tortoise/aerich/pull/272
[#271]: https://github.com/tortoise/aerich/pull/271

### [0.8.0](../../releases/tag/v0.8.0) - 2024-12-04

Expand Down
6 changes: 3 additions & 3 deletions aerich/inspectdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def translate(self) -> ColumnInfoDict:
length = ", ".join(length_parts) + ", "
if self.null:
null = "null=True, "
if self.default is not None:
if self.default is not None and not self.pk:
if self.data_type in ("tinyint", "INT"):
default = f"default={'True' if self.default == '1' else 'False'}, "
elif self.data_type == "bool":
Expand Down Expand Up @@ -158,11 +158,11 @@ def char_field(cls, **kwargs) -> str:

@classmethod
def int_field(cls, **kwargs) -> str:
return "{name} = fields.IntField({pk}{index}{comment})".format(**kwargs)
return "{name} = fields.IntField({pk}{index}{default}{comment})".format(**kwargs)

@classmethod
def smallint_field(cls, **kwargs) -> str:
return "{name} = fields.SmallIntField({pk}{index}{comment})".format(**kwargs)
return "{name} = fields.SmallIntField({pk}{index}{default}{comment})".format(**kwargs)

@classmethod
def bigint_field(cls, **kwargs) -> str:
Expand Down
5 changes: 3 additions & 2 deletions aerich/inspectdb/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def __init__(self, conn: "BasePostgresClient", tables: list[str] | None = None)
@property
def field_map(self) -> FieldMapDict:
return {
"int2": self.smallint_field,
"int4": self.int_field,
"int8": self.int_field,
"int8": self.bigint_field,
"smallint": self.smallint_field,
"bigint": self.bigint_field,
"varchar": self.char_field,
"text": self.text_field,
"bigint": self.bigint_field,
"timestamptz": self.datetime_field,
"float4": self.float_field,
"float8": self.float_field,
Expand Down

0 comments on commit f5d7d56

Please sign in to comment.