diff --git a/datalad_registry/models.py b/datalad_registry/models.py index a6127fc0..8827a3d3 100644 --- a/datalad_registry/models.py +++ b/datalad_registry/models.py @@ -98,9 +98,9 @@ class URLMetadata(db.Model): # type: ignore # Extractor and extraction parameters extractor_name = db.Column(db.String(100), nullable=False) extractor_version = db.Column(db.String(60), nullable=False) - extraction_parameter = db.Column(db.JSON, nullable=False) + extraction_parameter = db.Column(JSONB, nullable=False) - extracted_metadata = db.Column(db.JSON, nullable=False) + extracted_metadata = db.Column(JSONB, nullable=False) # The ID of the associated RepoUrl url_id = db.Column(db.Integer, db.ForeignKey("repo_url.id"), nullable=False) diff --git a/migrations/versions/029941610de0_change_all_json_columns_to_jsonb.py b/migrations/versions/029941610de0_change_all_json_columns_to_jsonb.py new file mode 100644 index 00000000..3d7d64ac --- /dev/null +++ b/migrations/versions/029941610de0_change_all_json_columns_to_jsonb.py @@ -0,0 +1,48 @@ +"""Change all JSON columns to JSONB + +Revision ID: 029941610de0 +Revises: e35239d06d44 +Create Date: 2024-02-23 06:24:15.776236 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = "029941610de0" +down_revision = "e35239d06d44" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("url_metadata", schema=None) as batch_op: + batch_op.alter_column( + "extraction_parameter", + existing_type=postgresql.JSON(astext_type=sa.Text()), + type_=postgresql.JSONB(astext_type=sa.Text()), + existing_nullable=False, + ) + batch_op.alter_column( + "extracted_metadata", + existing_type=postgresql.JSON(astext_type=sa.Text()), + type_=postgresql.JSONB(astext_type=sa.Text()), + existing_nullable=False, + ) + + +def downgrade(): + with op.batch_alter_table("url_metadata", schema=None) as batch_op: + batch_op.alter_column( + "extracted_metadata", + existing_type=postgresql.JSONB(astext_type=sa.Text()), + type_=postgresql.JSON(astext_type=sa.Text()), + existing_nullable=False, + ) + batch_op.alter_column( + "extraction_parameter", + existing_type=postgresql.JSONB(astext_type=sa.Text()), + type_=postgresql.JSON(astext_type=sa.Text()), + existing_nullable=False, + )