-- *********************************************************************
-- Update Database Script
-- *********************************************************************
-- Change Log: ./docs/db/changelog/changesets/liveness-check-proxy/db.changelog-module.xml
-- Ran at: 4/7/26, 4:48 PM
-- Against: null@offline:postgresql
-- Liquibase version: 4.33.0
-- *********************************************************************

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::1::Jan Pesek
-- Create a new table audit_log
CREATE TABLE audit_log (audit_log_id VARCHAR(36) NOT NULL, application_name VARCHAR(256) NOT NULL, audit_level VARCHAR(32) NOT NULL, audit_type VARCHAR(256), timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), message TEXT NOT NULL, exception_message TEXT, stack_trace TEXT, param TEXT, calling_class VARCHAR(256) NOT NULL, thread_name VARCHAR(256) NOT NULL, version VARCHAR(256), build_time TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT audit_log_pkey PRIMARY KEY (audit_log_id));

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::2::Jan Pesek
-- Create a new index on audit_log(timestamp_created)
CREATE INDEX audit_log_timestamp ON audit_log(timestamp_created);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::3::Jan Pesek
-- Create a new index on audit_log(application_name)
CREATE INDEX audit_log_application ON audit_log(application_name);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::4::Jan Pesek
-- Create a new index on audit_log(audit_level)
CREATE INDEX audit_log_level ON audit_log(audit_level);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::5::Jan Pesek
-- Create a new index on audit_log(audit_type)
CREATE INDEX audit_log_type ON audit_log(audit_type);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::6::Jan Pesek
-- Create a new table audit_param
CREATE TABLE audit_param (audit_log_id VARCHAR(36) NOT NULL, param_key VARCHAR(256), param_value VARCHAR(4000), timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), CONSTRAINT audit_param_pkey PRIMARY KEY (audit_log_id));

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::8::Jan Pesek
-- Create a new index on audit_param(timestamp_created)
CREATE INDEX audit_param_timestamp ON audit_param(timestamp_created);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::9::Jan Pesek
-- Create a new index on audit_log(param_key)
CREATE INDEX audit_param_key ON audit_param(param_key);

-- Changeset liveness-check-proxy/0.1.x/20240412-audit.xml::10::Jan Pesek
-- Create a new index on audit_log(param_value)
CREATE INDEX audit_param_value ON audit_param(param_value);

-- Changeset liveness-check-proxy/0.1.x/20240617-enrollment-table.xml::1::Jan Pesek
-- Create a new table lcp_enrollment
CREATE TABLE lcp_enrollment (id VARCHAR(36) NOT NULL, user_id VARCHAR(255) NOT NULL, external_id VARCHAR(255), timestamp_first_enrolled TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), timestamp_last_enrolled TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), CONSTRAINT lcp_enrollment_pkey PRIMARY KEY (id));

-- Changeset liveness-check-proxy/0.1.x/20240821-security.xml::1::Jan Pesek
-- Create a new table lcp_user for spring security
CREATE TABLE lcp_user (username VARCHAR(50) NOT NULL, password VARCHAR(500) NOT NULL, enabled BOOLEAN NOT NULL, CONSTRAINT lcp_user_pkey PRIMARY KEY (username));

-- Changeset liveness-check-proxy/0.1.x/20240821-security.xml::2::Jan Pesek
-- Create a new table lcp_authority for spring security
CREATE TABLE lcp_authority (username VARCHAR(50) NOT NULL, authority VARCHAR(50) NOT NULL, CONSTRAINT lcp_user_username_fk FOREIGN KEY (username) REFERENCES lcp_user(username));

-- Changeset liveness-check-proxy/0.1.x/20240821-security.xml::3::Jan Pesek
-- Create a new unique index on lcp_authority(username, authority)
CREATE UNIQUE INDEX username_authority_idx ON lcp_authority(username, authority);

-- Changeset liveness-check-proxy/1.0.x/20240730-add-tag-1.0.0.xml::1::Lubos Racansky
-- Changeset liveness-check-proxy/1.1.x/20250520-shedlock.xml::1::Lubos Racansky
-- Create a new table shedlock
CREATE TABLE shedlock (name VARCHAR(64) NOT NULL, lock_until TIMESTAMP WITHOUT TIME ZONE NOT NULL, locked_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, locked_by VARCHAR(255) NOT NULL, CONSTRAINT shedlock_pkey PRIMARY KEY (name));

-- Changeset liveness-check-proxy/1.3.x/20260407-add-subject-id-to-audit-log.xml::1::Pavel Sindelar
-- Add column subject_id to audit_log
ALTER TABLE audit_log ADD subject_id VARCHAR(256);

-- Changeset liveness-check-proxy/1.3.x/20260407-add-subject-id-to-audit-log.xml::2::Pavel Sindelar
-- Create index on audit_log(subject_id)
CREATE INDEX audit_log_subject_id_idx ON audit_log(subject_id);

-- Changeset liveness-check-proxy/1.3.x/20260517-add-onboarding-event.xml::1::Michal Rozehnal
-- Add column timestamp_onboarding_event to table lcp_enrollment
ALTER TABLE lcp_enrollment ADD timestamp_onboarding_event TIMESTAMP WITHOUT TIME ZONE;

-- Changeset liveness-check-proxy/1.3.x/20260517-add-onboarding-event.xml::2::Michal Rozehnal
-- Create index lcp_enrollment_external_id_idx
CREATE INDEX lcp_enrollment_external_id_idx ON lcp_enrollment(external_id);

