-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc/md: add schema monitoring drift detection doc (#3082)
- Loading branch information
Showing
4 changed files
with
119 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Drift Detection | ||
--- | ||
|
||
## Schema Drift | ||
|
||
Schema migrations on production databases should ideally be automated within CI/CD pipelines, keeping developers from | ||
needing root access. However, this setup isn't always the case, leading to **Schema Drift**, where database schemas | ||
drift from their intended state, causing inconsistencies and issues. | ||
|
||
Schema drift is dangerous because it can lead to unexpected behavior in applications, data corruption, and even system outages. | ||
When the actual database schema deviates from the expected schema, queries may fail, data integrity constraints may be violated, | ||
and application logic may break. Additionally, schema migrations are planned based on the assumption the target | ||
database is in a specific state and may fail and cause unknown side effects. This can result in hard-to-debug issues and | ||
degraded system performance, ultimately affecting the reliability and stability of your application. | ||
|
||
You can use Atlas [Schema Monitoring](/monitoring) to detect schema drift and ensure your database schema are always in sync with their | ||
intended state. Atlas schema monitoring automatically detects schema drift by comparing the actual database schema with the | ||
intended schema. If a drift is detected, Atlas will notify you and provide detailed information about the drift, including | ||
an ERD, HCL and SQL of the diff. | ||
|
||
#### Prerequisites: | ||
- [Migration directory](/cloud/directories) in atlas cloud | ||
|
||
#### Creating desired database schema | ||
|
||
First, we will need to deploy our migration directory to a target database. This will be our desired state. | ||
|
||
To [deploy](/cloud/deployment), create the next `atlas.hcl` file: | ||
```hcl | ||
env { | ||
name = atlas.env | ||
url = "docker://mysql/8/test" | ||
migration { | ||
dir = "atlas://<your-migration-directory>" | ||
} | ||
} | ||
``` | ||
|
||
And run the following command: | ||
|
||
```shell | ||
atlas migrate apply --env local | ||
``` | ||
|
||
|
||
#### Enabling Drift Detection | ||
|
||
Atlas enables you to automatically monitor schema drifts by periodically checking if your deployed database schema align with the desired schema. | ||
|
||
To enable periodic inspection, go the **settings** tab of the database you want to monitor and enable the **Periodic Inspection** toggle. | ||
This will instruct Atlas to periodically take snapshots of the database schema. | ||
<details> | ||
<summary>Screenshot Example</summary> | ||
|
||
![](https://atlasgo.io/uploads/cloud/monitoring/periodic-inspection.png) | ||
</details> | ||
|
||
Now, you can enable drift detection by toggling the **Drift Detection** switch, | ||
you will need to choose which migration directory and database target to compare against as the desired state. | ||
|
||
<details> | ||
<summary>Screenshot Example</summary> | ||
|
||
![](https://atlasgo.io/uploads/cloud/monitoring/enable-drift.png) | ||
</details> | ||
|
||
Once enabled, if there is a drift, Atlas will provide you with detailed information about the drift, including an ERD, HCL and SQL diff. | ||
|
||
You can see the drift in the **Changelog** tab. | ||
|
||
<details> | ||
<summary>Screenshot Example</summary> | ||
|
||
![](https://atlasgo.io/uploads/cloud/monitoring/diff-sql.png) | ||
</details> | ||
|
||
And you can also see the drift in the deployed database itself. | ||
|
||
<details> | ||
<summary>Screenshot Example</summary> | ||
|
||
![](https://atlasgo.io/uploads/cloud/monitoring/database-drift.png) | ||
</details> | ||
|
||
|
||
### Notifications | ||
|
||
You can instruct Atlas to notify you if there is a drift on the target database. Atlas supports various channels, such as Slack, | ||
Workplace or by a plain webhook. | ||
|
||
<details> | ||
<summary>Screenshot Example</summary> | ||
|
||
![](https://atlasgo.io/uploads/cloud/monitoring/webhooks.png) | ||
![](https://atlasgo.io/uploads/cloud/images/drift-webhook.png) | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters