"""create_resource_metadata_table

Revision ID: c6df714edd16
Revises: 6bb9c3509892
Create Date: 2026-02-09 11:42:36.813994

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'c6df714edd16'
down_revision = '6bb9c3509892'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('resource_metadata',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('service_name', sa.String(), nullable=True),
    sa.Column('resource_attributes', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
    sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_resource_metadata_service_name'), 'resource_metadata', ['service_name'], unique=False)
    op.add_column('spans', sa.Column('resource_id', sa.String(), nullable=True))
    op.create_index(op.f('ix_spans_resource_id'), 'spans', ['resource_id'], unique=False)
    op.create_foreign_key('fk_spans_resource_id', 'spans', 'resource_metadata', ['resource_id'], ['id'])
    op.add_column('trace_metadata', sa.Column('root_span_resource_id', sa.String(), nullable=True))
    op.create_index(op.f('ix_trace_metadata_root_span_resource_id'), 'trace_metadata', ['root_span_resource_id'], unique=False)
    op.create_foreign_key('fk_trace_metadata_root_span_resource_id', 'trace_metadata', 'resource_metadata', ['root_span_resource_id'], ['id'])
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('fk_trace_metadata_root_span_resource_id', 'trace_metadata', type_='foreignkey')
    op.drop_index(op.f('ix_trace_metadata_root_span_resource_id'), table_name='trace_metadata')
    op.drop_column('trace_metadata', 'root_span_resource_id')
    op.drop_constraint('fk_spans_resource_id', 'spans', type_='foreignkey')
    op.drop_index(op.f('ix_spans_resource_id'), table_name='spans')
    op.drop_column('spans', 'resource_id')
    op.drop_index(op.f('ix_resource_metadata_service_name'), table_name='resource_metadata')
    op.drop_table('resource_metadata')
    # ### end Alembic commands ###
