<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">



  <changeSet id="0001" author="adel.ka">
    <comment>add schema auth</comment>
    <sql>
      CREATE SCHEMA IF NOT EXISTS auth;
      ALTER SCHEMA auth OWNER TO ervu_business_metrics;
    </sql>
  </changeSet>

  <changeSet id="0002" author="adel.ka">
    <comment>add table active_session</comment>
    <sql>
      CREATE TABLE IF NOT EXISTS auth.active_session (
      session_id VARCHAR(128) NOT NULL,
      domain_id VARCHAR(128) NOT NULL,
      user_id VARCHAR(128) NOT NULL,
      ip_address VARCHAR(64),

      CONSTRAINT pk_active_session PRIMARY KEY (session_id, domain_id)
      );

      ALTER TABLE auth.active_session OWNER TO ervu_business_metrics;

      COMMENT ON TABLE auth.active_session IS 'Активные сессии пользователей';
      COMMENT ON COLUMN auth.active_session.session_id IS 'Идентификатор сессии';
      COMMENT ON COLUMN auth.active_session.domain_id IS 'Идентификатор домена';
      COMMENT ON COLUMN auth.active_session.user_id IS 'Идентификатор пользователя';
      COMMENT ON COLUMN auth.active_session.ip_address IS 'IP-адрес пользователя';
    </sql>
  </changeSet>

  <changeSet id="0003" author="adel.ka">
    <comment>add shedlock table</comment>
    <sql>
      CREATE TABLE IF NOT EXISTS ervu_business_metrics.shedlock (
      name VARCHAR(255),
      lock_until TIMESTAMP WITHOUT TIME ZONE,
      locked_at TIMESTAMP WITHOUT TIME ZONE,
      locked_by VARCHAR(255),

      CONSTRAINT shedlock_pk PRIMARY KEY (name)
      );

      ALTER TABLE ervu_business_metrics.shedlock OWNER TO ervu_business_metrics;

      COMMENT ON TABLE ervu_business_metrics.shedlock IS 'Таблица для хранения блокировок ShedLock';
      COMMENT ON COLUMN ervu_business_metrics.shedlock.name IS 'Имя ресурса блокировки';
      COMMENT ON COLUMN ervu_business_metrics.shedlock.lock_until IS 'Время, до которого действует блокировка';
      COMMENT ON COLUMN ervu_business_metrics.shedlock.locked_at IS 'Время создания блокировки';
      COMMENT ON COLUMN ervu_business_metrics.shedlock.locked_by IS 'Идентификатор узла, установившего блокировку';
    </sql>
  </changeSet>

</databaseChangeLog>