-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from gbdlin/feature/store-plugin-upload-path
Added `file_field` in version
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
plugin_store/database/migrations/versions/492a599cd718_version_uniqueness.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""empty message | ||
Revision ID: 492a599cd718 | ||
Revises: abe90daeb874 | ||
Create Date: 2023-06-13 22:05:19.849032 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "492a599cd718" | ||
down_revision = "abe90daeb874" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
with op.batch_alter_table("artifacts") as batch_op_artifacts: | ||
batch_op_artifacts.alter_column( | ||
"visible", existing_type=sa.BOOLEAN(), nullable=True, existing_server_default=sa.text("'1'") | ||
) | ||
with op.batch_alter_table("versions") as batch_op_versions: | ||
batch_op_versions.add_column(sa.Column("file", sa.Text(), nullable=True)) | ||
batch_op_versions.create_unique_constraint("unique_version_artifact_id_name", ["artifact_id", "name"]) | ||
|
||
|
||
def downgrade() -> None: | ||
with op.batch_alter_table("versions") as batch_op_versions: | ||
batch_op_versions.drop_constraint("unique_version_artifact_id_name", type_="unique") | ||
batch_op_versions.drop_column("versions", "file") | ||
with op.batch_alter_table("artifacts") as batch_op_artifacts: | ||
batch_op_artifacts.alter_column( | ||
"artifacts", "visible", existing_type=sa.BOOLEAN(), nullable=False, existing_server_default=sa.text("'1'") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
from sqlalchemy import Column, ForeignKey, Integer, Text | ||
from sqlalchemy import Column, ForeignKey, Integer, Text, UniqueConstraint | ||
|
||
import constants | ||
from ..utils import TZDateTime | ||
from .Base import Base | ||
|
||
|
||
class Version(Base): | ||
__tablename__ = "versions" | ||
__table_args__ = (UniqueConstraint("artifact_id", "name", name="unique_version_artifact_id_name"),) | ||
|
||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
artifact_id = Column(Integer, ForeignKey("artifacts.id")) | ||
name = Column(Text) | ||
hash = Column(Text) | ||
file_field = Column("file", Text, nullable=True) | ||
|
||
created = Column("added_on", TZDateTime) | ||
|
||
@property | ||
def file_url(self): | ||
return f"{constants.CDN_URL}{self.download_path}" | ||
|
||
@property | ||
def file(self): | ||
return f"artifact_images/{self.hash}.zip" |