"""add_pipeline_info_3

Revision ID: c459994abfa8
Revises: abb18a379e62
Create Date: 2025-05-30 00:33:14.068312

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

# revision identifiers, used by Alembic.
revision = 'c459994abfa8'
down_revision = 'abb18a379e62'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('datasource_oauth_params',
    sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
    sa.Column('plugin_id', models.types.StringUUID(), nullable=False),
    sa.Column('provider', sa.String(length=255), nullable=False),
    sa.Column('system_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.PrimaryKeyConstraint('id', name='datasource_oauth_config_pkey'),
    sa.UniqueConstraint('plugin_id', 'provider', name='datasource_oauth_config_datasource_id_provider_idx')
    )
    op.create_table('datasource_providers',
    sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
    sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
    sa.Column('plugin_id', models.types.StringUUID(), nullable=False),
    sa.Column('provider', sa.String(length=255), nullable=False),
    sa.Column('auth_type', sa.String(length=255), nullable=False),
    sa.Column('encrypted_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id', name='datasource_provider_pkey'),
    sa.UniqueConstraint('plugin_id', 'provider', name='datasource_provider_plugin_id_provider_idx')
    )
    with op.batch_alter_table('pipeline_built_in_templates', schema=None) as batch_op:
        batch_op.add_column(sa.Column('chunk_structure', sa.String(length=255), nullable=False))
        batch_op.add_column(sa.Column('yaml_content', sa.Text(), nullable=False))
        batch_op.drop_column('pipeline_id')

    with op.batch_alter_table('pipeline_customized_templates', schema=None) as batch_op:
        batch_op.add_column(sa.Column('chunk_structure', sa.String(length=255), nullable=False))
        batch_op.add_column(sa.Column('yaml_content', sa.Text(), nullable=False))
        batch_op.drop_column('pipeline_id')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    with op.batch_alter_table('pipeline_customized_templates', schema=None) as batch_op:
        batch_op.add_column(sa.Column('pipeline_id', sa.UUID(), autoincrement=False, nullable=False))
        batch_op.drop_column('yaml_content')
        batch_op.drop_column('chunk_structure')

    with op.batch_alter_table('pipeline_built_in_templates', schema=None) as batch_op:
        batch_op.add_column(sa.Column('pipeline_id', sa.UUID(), autoincrement=False, nullable=False))
        batch_op.drop_column('yaml_content')
        batch_op.drop_column('chunk_structure')

    op.drop_table('datasource_providers')
    op.drop_table('datasource_oauth_params')
    # ### end Alembic commands ###
