Skip to content

Commit 2ed454e

Browse files
authored
Widen assets.size to BIGINT (#1429)
* BUG: widen assets.size to BIGINT The `assets.size` column was defined as `Integer` (int32), so registering a single file larger than ~2.1 GB failed on PostgreSQL with `value out of int32 range` during INSERT. Change the ORM column to `BigInteger` and add an alembic migration that runs `ALTER TABLE assets ALTER COLUMN size TYPE BIGINT` on PostgreSQL. SQLite is unaffected because its `INTEGER` affinity already stores 64-bit values. * MNT: format and lint
1 parent 995fa00 commit 2ed454e

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Write the date in place of the "Unreleased" in the case a new version is release
1111
from metadata responses when the request comes from a `python-tiled` client older than
1212
v0.2.13, whose `Asset` dataclass has no `size` field and would otherwise crash
1313
in `DataSource.from_json` with an unexpected keyword argument.
14+
- Widen `assets.size` from `INTEGER` (int32) to `BIGINT` (int64) so the
15+
server can register single files larger than ~2.1 GB without an
16+
`int32 out of range` error from PostgreSQL. Includes an alembic
17+
migration; SQLite is unaffected (its `INTEGER` affinity already stores
18+
64-bit values).
1419

1520

1621
## v0.2.13 (2026-07-08)

tiled/catalog/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# This is list of all valid revisions (from current to oldest).
88
ALL_REVISIONS = [
9+
"9bc9b57294b9",
910
"b93c79d197f4",
1011
"e8956581ecd5",
1112
"bf2fe0eb8ee8",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Widen assets.size to BigInteger
2+
3+
Revision ID: 9bc9b57294b9
4+
Revises: b93c79d197f4
5+
Create Date: 2026-07-09 14:32:49.251181
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "9bc9b57294b9"
14+
down_revision = "b93c79d197f4"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
connection = op.get_bind()
21+
if connection.engine.dialect.name == "postgresql":
22+
op.alter_column(
23+
"assets",
24+
"size",
25+
existing_type=sa.Integer(),
26+
type_=sa.BigInteger(),
27+
existing_nullable=True,
28+
)
29+
# SQLite: INTEGER affinity already stores 64-bit values, no schema change needed.
30+
31+
32+
def downgrade():
33+
connection = op.get_bind()
34+
if connection.engine.dialect.name == "postgresql":
35+
op.alter_column(
36+
"assets",
37+
"size",
38+
existing_type=sa.BigInteger(),
39+
type_=sa.Integer(),
40+
existing_nullable=True,
41+
)

tiled/catalog/orm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from sqlalchemy import (
44
JSON,
5+
BigInteger,
56
Boolean,
67
Column,
78
DateTime,
@@ -534,7 +535,7 @@ class Asset(Timestamped, Base):
534535
is_directory = Column(Boolean, nullable=False)
535536
hash_type = Column(Unicode(63), nullable=True)
536537
hash_content = Column(Unicode(1023), nullable=True)
537-
size = Column(Integer, nullable=True)
538+
size = Column(BigInteger, nullable=True)
538539

539540
# # many-to-many relationship to Asset, bypassing the `Association` class
540541
data_sources: Mapped[List["DataSource"]] = relationship(

0 commit comments

Comments
 (0)