# `sc_crawler.archive_rules`

> Archive rules: the records replaced by another record or deliberately dropped.

# `sc_crawler.archive_rules`

A record gets the [ARCHIVED](https://docs.sparecores.com/crawler/reference/table_fields.md#status) status only
through the [archive_rules](#archive_rules) listed
here, which are applied by the `pull` and `sync` commands on every run:

- Each old → new pair is one [ArchiveRule](https://docs.sparecores.com/crawler/reference/tables.md#archiverule):
  a rename or re-key is one rule, a split is one rule per successor with
  the same `match`, a merge is one rule per old record with the same
  `successor`. A dropped record has one rule with an empty `successor`
  and a `reason`.
- `match` is the primary key of the record to archive, or a subset of its
  columns to archive every record with those values (a dict column such as
  `config` matches only when the whole dict is equal). `successor` gives
  the new values of the same columns. Give enum columns by the value of the
  member (e.g. `spot` for `allocation`), not by its name as stored in the
  database (`SPOT`).
- Child records, i.e. records referencing an archived record in their
  primary key (e.g. the zones and prices of a region, or the scores of a
  benchmark), are archived as well without their own rules. Add a rule
  for a child record only when its successor does not follow from the
  rules of its parents (e.g. the Hetzner zones below).
- Never remove a rule that has archived records. Rules removed from here
  are kept as `INACTIVE` in the `archive_rule` table.

The methods matching and applying the rules are on
[ScModel](https://docs.sparecores.com/crawler/reference/table_bases.md#scmodel) and
[ArchiveRule](https://docs.sparecores.com/crawler/reference/tables.md#archiverule), e.g.
[archived_by](https://docs.sparecores.com/crawler/reference/table_bases.md#scmodelarchived_by) tracing which rules
archived a record.

Use `ARCHIVED` only for our own decisions about the identity of a record,
see [Status](https://docs.sparecores.com/crawler/reference/table_fields.md#status) on how it differs from
`INACTIVE` and `RETIRED`.

**Attributes:**

- [**archive_rules**](#archive_rules) ([`List`](https://docs.python.org/3/library/typing.html#typing.List)`[`[`ArchiveRule`](https://docs.sparecores.com/crawler/reference/tables.md#archiverule)`]`) – All archive rules, applied by the `pull` and `sync` commands.

## attr <code class="doc-name">archive_rules</code> [archive_rules.py:73–112](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/archive_rules.py#L73-L112)

```python
archive_rules: List[ArchiveRule] = [*[ArchiveRule(table_name='region', match={'vendor_id': 'hcloud', 'region_id': old}, successor={'vendor_id': 'hcloud', 'region_id': new}, reason=_HCLOUD_REASON) for old, new in _HCLOUD_DATACENTER_TO_LOCATION.items()], *[ArchiveRule(table_name='zone', match={'vendor_id': 'hcloud', 'region_id': old, 'zone_id': old}, successor={'vendor_id': 'hcloud', 'region_id': new, 'zone_id': new}, reason=_HCLOUD_REASON) for old, new in _HCLOUD_DATACENTER_TO_LOCATION.items()], *[ArchiveRule(table_name='server', match={'vendor_id': 'gcp', 'server_id': old}, successor={'vendor_id': 'gcp', 'server_id': new}, reason='Same machine as its successor: GCP renamed it and keeps the old name as an alias.') for old, new in _GCP_RENAMED_MACHINE_TYPES.items()], ArchiveRule(table_name='benchmark', match={'benchmark_id': 'app:static_web'}, successor={'benchmark_id': 'static_web:rps'}, reason='Replaced by the benchmarks of the static_web framework.')]
```

All archive rules, applied by the `pull` and `sync` commands.
