Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all JSON columns to JSONB #311

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datalad_registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)