-- DeploymentConfig 지원을 위한 Table 추가
CREATE TABLE cmoa_deploymentconfig_base(
    kube_flatting_time    bigint,
    cluster_id    varchar(255),
    kind    varchar(30),
    metadata_uid    varchar(40),
    row_index    int,
    kind_status    varchar(50),
    metadata_creationTimestamp    varchar(25),
    metadata_name    text,
    metadata_namespace    text,
    metadata_resourceVersion    text,
    spec_replicas    text,
    spec_template_spec_containers_image    text,
    spec_template_metadata_labels    text,
    status_availableReplicas    text,
    status_updatedReplicas    text,
    status_replicas    text,
    status_unavailableReplicas    text,
    create_time    timestamp    default now(),
    PRIMARY KEY (kube_flatting_time, cluster_id, kind, metadata_uid, row_index)
);

-- ReplicationController 지원을 위한 Table 추가
CREATE TABLE cmoa_replicationcontroller_base    (
    kube_flatting_time    bigint,
    cluster_id    varchar(255),
    kind    varchar(30),
    metadata_uid    varchar(40),
    row_index    int,
    kind_status    varchar(50),
    metadata_annotations    text,
    metadata_creationtimestamp    varchar(25),
    metadata_labels    text,
    metadata_name    text,
    metadata_namespace    text,
    metadata_resourceversion    text,
    spec_replicas    text,
    status_availablereplicas    text,
    status_readyreplicas    text,
    status_replicas    text,
    status_observedgeneration    text,
    create_time    timestamp    default now(),
    PRIMARY KEY (kube_flatting_time, cluster_id, kind, metadata_uid, row_index)
);

create table public.audit_log
(
    id           bigserial
        constraint audit_log_pk
            primary key,
    created_date timestamp not null,
    user_id      varchar   not null,
    type         varchar   not null,
    menu_path    varchar   not null,
    result       boolean   not null,
    target       jsonb
);



-- DeploymentConfig Event 관련 metric meta 추가
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message) VALUES('kube_event_deploymentconfig','Kubernetes DeploymentConfig Event','Kubernetes DeploymentConfig Event','count by (xm_clst_id,xm_namespace,entity_type,involved_kind,involved_name,reason,type) (imxc_kubernetes_event_in_last_min{involved_kind="DeploymentConfig", {filter} })','Event','Workload','','true','false','CLST:{{$labels.xm_clst_id}} NS:{{$labels.xm_namespace}}  Reason : {{$labels.reason}} Level : {{$labels.type}} ');
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message) VALUES('host_count','Host Count','Host Count','count(node_boot_time_seconds{is_host="true"})','Host','System','','true','false','Host Count : {{humanize $value}}');
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message) VALUES('host_alive','Host Alive','Host Alive','count(node_boot_time_seconds{is_host="true", {filter}})','Host','System','','true','false','Host Alive : {{$labels.instance}}');
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message) VALUES('host_dead','Host Dead','Host Dead','absent(node_boot_time_seconds{is_host="true", {filter}})','Host','System','','true','false','Host Dead : {{$labels.instance}}');

commit;
