yegor256/0rsk

View on GitHub
liquibase/2019/004-triple.xml

Summary

Maintainability
Test Coverage
<?xml version="1.0"?>
<!--
(The MIT License)

Copyright (c) 2019-2024 Yegor Bugayenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd" logicalFilePath="001-initial-schema.xml">
  <changeSet id="004" author="yegor256">
    <sql>
      DROP TABLE link;
      DROP TABLE ranked;
      DROP TABLE agenda;
      DROP TABLE cause;
      DROP TABLE risk;
      DROP TABLE effect;
      DROP TABLE plan;
    </sql>
    <sql>
      CREATE TYPE ptype AS ENUM ('Cause', 'Risk', 'Effect', 'Plan');
      CREATE TABLE part (
        id SERIAL PRIMARY KEY,
        project INT NOT NULL REFERENCES project(id),
        type ptype NOT NULL,
        text VARCHAR(160) NOT NULL,
        created TIMESTAMPTZ DEFAULT now() NOT NULL,
        UNIQUE(project, text),
        CHECK (text &lt;&gt; '')
      );
      CREATE INDEX idx_part1 ON part(project, created);
    </sql>
    <sql>
      CREATE TABLE cause (
        id INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        PRIMARY KEY(id)
      );
    </sql>
    <sql>
      CREATE TABLE risk (
        id INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        probability INT NOT NULL DEFAULT 4,
        PRIMARY KEY(id),
        CHECK (probability &gt;= 1),
        CHECK (probability &lt;= 9)
      );
      CREATE INDEX idx_risk1 ON risk(probability);
    </sql>
    <sql>
      CREATE TABLE effect (
        id INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        impact INT NOT NULL DEFAULT 4,
        PRIMARY KEY(id),
        CHECK (impact &gt;= 1),
        CHECK (impact &lt;= 9)
      );
      CREATE INDEX idx_effect1 ON effect(impact);
    </sql>
    <sql>
      CREATE TABLE plan (
        id INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        part INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        schedule VARCHAR(32) NOT NULL DEFAULT 'weekly',
        completed TIMESTAMPTZ DEFAULT now() NOT NULL,
        UNIQUE(id, part),
        CHECK (schedule &lt;&gt; '')
      );
      CREATE INDEX idx_plan1 ON plan(part);
    </sql>
    <sql>
      CREATE TABLE triple (
        id SERIAL PRIMARY KEY,
        cause INT NOT NULL REFERENCES cause(id),
        risk INT NOT NULL REFERENCES risk(id),
        effect INT NOT NULL REFERENCES effect(id),
        created TIMESTAMPTZ DEFAULT now() NOT NULL,
        UNIQUE(cause, risk, effect)
      );
      CREATE INDEX idx_triple1 ON triple(cause, risk, effect);
    </sql>
    <sql>
      CREATE TABLE task (
        id SERIAL PRIMARY KEY,
        plan INT NOT NULL REFERENCES part(id) ON DELETE CASCADE,
        created TIMESTAMPTZ DEFAULT now() NOT NULL,
        UNIQUE(plan)
      );
      CREATE INDEX idx_task1 ON task(plan);
    </sql>
  </changeSet>
</databaseChangeLog>