"""migrate_rels_attr_projects_options_value

Revision ID: 0253
Revises: 0252
Create Date: 2023-06-23 11:17:10.998559

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = '0253'
down_revision = '0252'
branch_labels = None
depends_on = None


def upgrade():
    op.execute("""
        UPDATE attributes
        SET options = jsonb_strip_nulls(jsonb_set(jsonb_set(options, '{project}', jsonb_path_query_first(options, '$.projects.id')), '{projects}', 'null'::jsonb))
        WHERE type_name = 'relationships' AND options ? 'projects'
    """)


def downgrade():
    pass
