-- Add migration script here
CREATE TABLE IF NOT exists scouter.drift_alert (
  created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
  name text not null,
  space text not null,
  version text not null,
  entity_name text not null,
  alert jsonb not null default '{}',
  active boolean not null default true,
  id integer generated by default as identity,
  drift_type TEXT,
  updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
  UNIQUE (created_at, name, space, version)
)
PARTITION BY RANGE (created_at);

CREATE INDEX idx_drift_alert_created_at_space_name_version
ON scouter.drift_alert (created_at, space, name, version);

SELECT scouter.create_parent(
    'scouter.drift_alert',
    'created_at',
    '1 day'
);

UPDATE scouter.part_config SET retention = '365 days' WHERE parent_table = 'scouter.drift_alert';
