Skip to content

Commit

Permalink
🚚 Add a size column to dobject (#32)
Browse files Browse the repository at this point in the history
* 🚚 Add a size column to dobject

* 📝 Fix type anno another time

* 🚚 Add migration and migrate testdb
  • Loading branch information
falexwolf authored Sep 25, 2022
1 parent 2613758 commit 66618cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lnschema_core/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class dobject(SQLModel, table=True): # type: ignore
name: Optional[str] = Field(index=True)
suffix: Optional[str] = Field(default=None, index=True)
dtransform_id: str = Field(foreign_key="dtransform.id", index=True)
size: Optional[float] = Field(default=None, index=True)
"""Size in bytes."""
storage_id: str = Field(foreign_key="storage.id", index=True)
created_at: datetime = CreatedAt
updated_at: Optional[datetime] = UpdatedAt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""v0.8.0.
Revision ID: 7e8f7b30792e
Revises: 1f29517759b7
Create Date: 2022-09-25 20:39:03.626212
"""
import sqlalchemy as sa # noqa
import sqlmodel # noqa
from alembic import op

# revision identifiers, used by Alembic.
revision = "7e8f7b30792e"
down_revision = "1f29517759b7"
branch_labels = None
depends_on = None


def upgrade() -> None:
with op.batch_alter_table("dobject", schema=None) as batch_op:
batch_op.add_column(sa.Column("size", sa.Float(), nullable=True))
batch_op.create_index(batch_op.f("ix_dobject_size"), ["size"], unique=False)


def downgrade() -> None:
with op.batch_alter_table("dobject", schema=None) as batch_op:
batch_op.drop_index(batch_op.f("ix_dobject_size"))
batch_op.drop_column("size")
Binary file modified tests/testdb.lndb
Binary file not shown.

0 comments on commit 66618cb

Please sign in to comment.