-- Model configuration and versioning
CREATE TABLE IF NOT EXISTS model_config (
    id SERIAL PRIMARY KEY,
    model_name VARCHAR(255) NOT NULL,
    model_type VARCHAR(100) NOT NULL,
    s3_bucket VARCHAR(255) NOT NULL,
    s3_region VARCHAR(50) NOT NULL,
    cache_path VARCHAR(500) NOT NULL,
    is_active BOOLEAN DEFAULT true,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS model_versions (
    id SERIAL PRIMARY KEY,
    model_config_id INTEGER REFERENCES model_config(id),
    version VARCHAR(50) NOT NULL,
    s3_path VARCHAR(500) NOT NULL,
    checksum VARCHAR(64),
    training_date TIMESTAMP,
    performance_metrics JSONB,
    is_current BOOLEAN DEFAULT false,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_model_config_name ON model_config(model_name);
CREATE INDEX idx_model_versions_current ON model_versions(is_current);