# contract_flowthrough

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `contract_flowthrough` (
  `contract_flowthrough_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `contract_id` mediumint unsigned NOT NULL,
  `reference_flowthrough_calculation_id` tinyint unsigned NOT NULL,
  `flowthrough_rate` decimal(5,2) NOT NULL,
  `flowthrough_status` enum('active','shutoff','paused') NOT NULL DEFAULT 'active',
  `has_automatic_shutoff` tinyint(1) NOT NULL DEFAULT '1',
  `recoupment_cap` bigint DEFAULT NULL,
  `previous_flowthrough_status` enum('active','shutoff','paused') DEFAULT NULL,
  `status_last_modified_by` varchar(180) DEFAULT NULL,
  `status_last_modified` datetime DEFAULT NULL,
  `created_by` varchar(180) NOT NULL,
  `created_at` datetime NOT NULL,
  `last_modified_by` varchar(180) NOT NULL,
  `last_modified` datetime NOT NULL,
  `deleted_by` varchar(180) DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL,
  PRIMARY KEY (`contract_flowthrough_id`),
  KEY `fk_contract_flowthrough_contract` (`contract_id`),
  KEY `fk_contract_flowthrough_reference_flowthrough_calculation` (`reference_flowthrough_calculation_id`),
  CONSTRAINT `fk_contract_flowthrough_contract` FOREIGN KEY (`contract_id`) REFERENCES `contract` (`contract_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_contract_flowthrough_reference_flowthrough_calculation` FOREIGN KEY (`reference_flowthrough_calculation_id`) REFERENCES `reference_flowthrough_calculation` (`reference_flowthrough_calculation_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
```

</details>

## Columns

| Name                                 | Type                              | Default | Nullable | Extra Definition | Children                                                        | Parents                                                                   | Comment |
| ------------------------------------ | --------------------------------- | ------- | -------- | ---------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------- | ------- |
| contract_flowthrough_id              | mediumint unsigned                |         | false    | auto_increment   | [contract_flowthrough_history](contract_flowthrough_history.md) |                                                                           |         |
| contract_id                          | mediumint unsigned                |         | false    |                  |                                                                 | [contract](contract.md)                                                   |         |
| created_at                           | datetime                          |         | false    |                  |                                                                 |                                                                           |         |
| created_by                           | varchar(180)                      |         | false    |                  |                                                                 |                                                                           |         |
| deleted_at                           | datetime                          |         | true     |                  |                                                                 |                                                                           |         |
| deleted_by                           | varchar(180)                      |         | true     |                  |                                                                 |                                                                           |         |
| flowthrough_rate                     | decimal(5,2)                      |         | false    |                  |                                                                 |                                                                           |         |
| flowthrough_status                   | enum('active','shutoff','paused') | active  | false    |                  |                                                                 |                                                                           |         |
| has_automatic_shutoff                | tinyint(1)                        | 1       | false    |                  |                                                                 |                                                                           |         |
| last_modified                        | datetime                          |         | false    |                  |                                                                 |                                                                           |         |
| last_modified_by                     | varchar(180)                      |         | false    |                  |                                                                 |                                                                           |         |
| previous_flowthrough_status          | enum('active','shutoff','paused') |         | true     |                  |                                                                 |                                                                           |         |
| recoupment_cap                       | bigint                            |         | true     |                  |                                                                 |                                                                           |         |
| reference_flowthrough_calculation_id | tinyint unsigned                  |         | false    |                  |                                                                 | [reference_flowthrough_calculation](reference_flowthrough_calculation.md) |         |
| status_last_modified                 | datetime                          |         | true     |                  |                                                                 |                                                                           |         |
| status_last_modified_by              | varchar(180)                      |         | true     |                  |                                                                 |                                                                           |         |

## Viewpoints

| Name                          | Definition                                 |
| ----------------------------- | ------------------------------------------ |
| [Flowthrough](viewpoint-0.md) | Tables relevant to processing flowthrough. |

## Constraints

| Name                                                      | Type        | Definition                                                                                                                             |
| --------------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| PRIMARY                                                   | PRIMARY KEY | PRIMARY KEY (contract_flowthrough_id)                                                                                                  |
| fk_contract_flowthrough_contract                          | FOREIGN KEY | FOREIGN KEY (contract_id) REFERENCES contract (contract_id)                                                                            |
| fk_contract_flowthrough_reference_flowthrough_calculation | FOREIGN KEY | FOREIGN KEY (reference_flowthrough_calculation_id) REFERENCES reference_flowthrough_calculation (reference_flowthrough_calculation_id) |

## Indexes

| Name                                                      | Definition                                                                                                       |
| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| PRIMARY                                                   | PRIMARY KEY (contract_flowthrough_id) USING BTREE                                                                |
| fk_contract_flowthrough_contract                          | KEY fk_contract_flowthrough_contract (contract_id) USING BTREE                                                   |
| fk_contract_flowthrough_reference_flowthrough_calculation | KEY fk_contract_flowthrough_reference_flowthrough_calculation (reference_flowthrough_calculation_id) USING BTREE |

## Triggers

| Name                                      | Definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| after_update_contract_flowthrough_history | CREATE TRIGGER after_update_contract_flowthrough_history AFTER UPDATE ON contract_flowthrough<br />FOR EACH ROW<br />BEGIN<br />    INSERT INTO `contract_flowthrough_history` (<br />        `contract_flowthrough_id`,<br />        `contract_id`,<br />        `reference_flowthrough_calculation_id`,<br />        `flowthrough_rate`,<br />        `flowthrough_status`,<br />        `has_automatic_shutoff`,<br />        `recoupment_cap`,<br />        `previous_flowthrough_status`,<br />        `status_last_modified_by`,<br />        `status_last_modified`,<br />        `created_by`,<br />        `created_at`,<br />        `last_modified_by`,<br />        `last_modified`,<br />        `deleted_by`,<br />        `deleted_at`<br />    ) VALUES (<br />        OLD.contract_flowthrough_id,<br />        OLD.contract_id,<br />        OLD.reference_flowthrough_calculation_id,<br />        OLD.flowthrough_rate,<br />        OLD.flowthrough_status,<br />        OLD.has_automatic_shutoff,<br />        OLD.recoupment_cap,<br />        OLD.previous_flowthrough_status,<br />        OLD.status_last_modified_by,<br />        OLD.status_last_modified,<br />        OLD.created_by,<br />        OLD.created_at,<br />        OLD.last_modified_by,<br />        OLD.last_modified,<br />        OLD.deleted_by,<br />        OLD.deleted_at<br />    );<br />END |

## Relations

![er](contract_flowthrough.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
