-- *********************************************************************
-- Update Database Script
-- *********************************************************************
-- Change Log: ./docs/db/changelog/changesets/liveness-check-proxy/db.changelog-module.xml
-- Ran at: 4/7/26, 4:50 PM
-- Against: null@offline:mssql
-- 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 datetime2 CONSTRAINT DF_audit_log_timestamp_created DEFAULT GETDATE(), message varchar (max) NOT NULL, exception_message varchar (max), stack_trace varchar (max), param varchar (max), calling_class varchar(256) NOT NULL, thread_name varchar(256) NOT NULL, version varchar(256), build_time datetime2, CONSTRAINT PK_AUDIT_LOG PRIMARY KEY (audit_log_id));
GO

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

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

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

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

-- 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 datetime2 CONSTRAINT DF_audit_param_timestamp_created DEFAULT GETDATE(), CONSTRAINT PK_AUDIT_PARAM PRIMARY KEY (audit_log_id));
GO

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

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

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

-- 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 datetime2 CONSTRAINT DF_lcp_enrollment_timestamp_first_enrolled DEFAULT GETDATE(), timestamp_last_enrolled datetime2 CONSTRAINT DF_lcp_enrollment_timestamp_last_enrolled DEFAULT GETDATE(), CONSTRAINT PK_LCP_ENROLLMENT PRIMARY KEY (id));
GO

-- 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 bit NOT NULL, CONSTRAINT PK_LCP_USER PRIMARY KEY (username));
GO

-- 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));
GO

-- 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 NONCLUSTERED INDEX username_authority_idx ON lcp_authority(username, authority);
GO

-- 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 datetime2 NOT NULL, locked_at datetime2 NOT NULL, locked_by varchar(255) NOT NULL, CONSTRAINT PK_SHEDLOCK PRIMARY KEY (name));
GO

-- 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);
GO

-- 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 NONCLUSTERED INDEX audit_log_subject_id_idx ON audit_log(subject_id);
GO

-- 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 datetime2;
GO

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