Remove Node.js cache files containing npm vulnerability data for vitest and vite packages
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
"""Add Docker management tables
|
||||
|
||||
Revision ID: 0011
|
||||
Revises: 0010
|
||||
Create Date: 2025-01-15
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0011_add_docker_management_tables'
|
||||
down_revision: Union[str, None] = '0010_remove_logs_foreign_keys'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add Docker-related columns to hosts table
|
||||
op.add_column('hosts', sa.Column('docker_enabled', sa.Boolean(), nullable=False, server_default=sa.text('0')))
|
||||
op.add_column('hosts', sa.Column('docker_version', sa.String(50), nullable=True))
|
||||
op.add_column('hosts', sa.Column('docker_status', sa.String(20), nullable=True))
|
||||
op.add_column('hosts', sa.Column('docker_last_collect_at', sa.DateTime(timezone=True), nullable=True))
|
||||
|
||||
# Create docker_containers table
|
||||
op.create_table(
|
||||
'docker_containers',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('host_id', sa.String(), nullable=False),
|
||||
sa.Column('container_id', sa.String(64), nullable=False),
|
||||
sa.Column('name', sa.String(255), nullable=False),
|
||||
sa.Column('image', sa.String(255), nullable=True),
|
||||
sa.Column('state', sa.String(20), nullable=False, server_default='unknown'),
|
||||
sa.Column('status', sa.String(255), nullable=True),
|
||||
sa.Column('health', sa.String(20), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('ports', sa.JSON(), nullable=True),
|
||||
sa.Column('labels', sa.JSON(), nullable=True),
|
||||
sa.Column('compose_project', sa.String(255), nullable=True),
|
||||
sa.Column('last_update_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(['host_id'], ['hosts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('ix_docker_containers_host_id', 'docker_containers', ['host_id'])
|
||||
op.create_index('ix_docker_containers_container_id', 'docker_containers', ['container_id'])
|
||||
|
||||
# Create docker_images table
|
||||
op.create_table(
|
||||
'docker_images',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('host_id', sa.String(), nullable=False),
|
||||
sa.Column('image_id', sa.String(64), nullable=False),
|
||||
sa.Column('repo_tags', sa.JSON(), nullable=True),
|
||||
sa.Column('size', sa.BigInteger(), nullable=True),
|
||||
sa.Column('created', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('last_update_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(['host_id'], ['hosts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('ix_docker_images_host_id', 'docker_images', ['host_id'])
|
||||
|
||||
# Create docker_volumes table
|
||||
op.create_table(
|
||||
'docker_volumes',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('host_id', sa.String(), nullable=False),
|
||||
sa.Column('name', sa.String(255), nullable=False),
|
||||
sa.Column('driver', sa.String(50), nullable=True),
|
||||
sa.Column('mountpoint', sa.Text(), nullable=True),
|
||||
sa.Column('scope', sa.String(20), nullable=True),
|
||||
sa.Column('last_update_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(['host_id'], ['hosts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('ix_docker_volumes_host_id', 'docker_volumes', ['host_id'])
|
||||
|
||||
# Create docker_alerts table
|
||||
op.create_table(
|
||||
'docker_alerts',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('host_id', sa.String(), nullable=False),
|
||||
sa.Column('container_name', sa.String(255), nullable=False),
|
||||
sa.Column('severity', sa.String(20), nullable=False, server_default='warning'),
|
||||
sa.Column('state', sa.String(20), nullable=False, server_default='open'),
|
||||
sa.Column('message', sa.Text(), nullable=True),
|
||||
sa.Column('opened_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column('closed_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('acknowledged_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('acknowledged_by', sa.String(100), nullable=True),
|
||||
sa.Column('last_notified_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['host_id'], ['hosts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('idx_docker_alerts_state_host', 'docker_alerts', ['state', 'host_id'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Drop Docker tables
|
||||
op.drop_index('idx_docker_alerts_state_host', 'docker_alerts')
|
||||
op.drop_table('docker_alerts')
|
||||
|
||||
op.drop_index('ix_docker_volumes_host_id', 'docker_volumes')
|
||||
op.drop_table('docker_volumes')
|
||||
|
||||
op.drop_index('ix_docker_images_host_id', 'docker_images')
|
||||
op.drop_table('docker_images')
|
||||
|
||||
op.drop_index('ix_docker_containers_container_id', 'docker_containers')
|
||||
op.drop_index('ix_docker_containers_host_id', 'docker_containers')
|
||||
op.drop_table('docker_containers')
|
||||
|
||||
# Remove Docker columns from hosts
|
||||
op.drop_column('hosts', 'docker_last_collect_at')
|
||||
op.drop_column('hosts', 'docker_status')
|
||||
op.drop_column('hosts', 'docker_version')
|
||||
op.drop_column('hosts', 'docker_enabled')
|
||||
@@ -0,0 +1,80 @@
|
||||
"""Add unique constraints to Docker tables.
|
||||
|
||||
Revision ID: 0012
|
||||
Revises: 0011
|
||||
Create Date: 2025-12-15
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0012'
|
||||
down_revision: Union[str, None] = '0011_add_docker_management_tables'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add unique constraints to Docker tables to prevent duplicates."""
|
||||
# First, clean up any existing duplicates before adding constraints
|
||||
|
||||
# For docker_containers: keep only the most recent entry per (host_id, container_id)
|
||||
op.execute("""
|
||||
DELETE FROM docker_containers
|
||||
WHERE id NOT IN (
|
||||
SELECT MAX(id) FROM docker_containers
|
||||
GROUP BY host_id, container_id
|
||||
)
|
||||
""")
|
||||
|
||||
# For docker_images: keep only the most recent entry per (host_id, image_id)
|
||||
op.execute("""
|
||||
DELETE FROM docker_images
|
||||
WHERE id NOT IN (
|
||||
SELECT MAX(id) FROM docker_images
|
||||
GROUP BY host_id, image_id
|
||||
)
|
||||
""")
|
||||
|
||||
# For docker_volumes: keep only the most recent entry per (host_id, name)
|
||||
op.execute("""
|
||||
DELETE FROM docker_volumes
|
||||
WHERE id NOT IN (
|
||||
SELECT MAX(id) FROM docker_volumes
|
||||
GROUP BY host_id, name
|
||||
)
|
||||
""")
|
||||
|
||||
# Now add unique constraints
|
||||
# Note: SQLite doesn't support adding constraints directly, so we use CREATE UNIQUE INDEX
|
||||
op.create_index(
|
||||
'uq_docker_containers_host_container',
|
||||
'docker_containers',
|
||||
['host_id', 'container_id'],
|
||||
unique=True
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'uq_docker_images_host_image',
|
||||
'docker_images',
|
||||
['host_id', 'image_id'],
|
||||
unique=True
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'uq_docker_volumes_host_name',
|
||||
'docker_volumes',
|
||||
['host_id', 'name'],
|
||||
unique=True
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Remove unique constraints from Docker tables."""
|
||||
op.drop_index('uq_docker_containers_host_container', table_name='docker_containers')
|
||||
op.drop_index('uq_docker_images_host_image', table_name='docker_images')
|
||||
op.drop_index('uq_docker_volumes_host_name', table_name='docker_volumes')
|
||||
Reference in New Issue
Block a user