From 21e835f3a632c1f1044a7be456ad1caeb8af4f6d Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 12 Jan 2021 16:24:22 +0100 Subject: [PATCH] Backend style guide: Document database patterns (#30219) * Backend style guide: Document database patterns Signed-off-by: Arve Knudsen * Wording Signed-off-by: Arve Knudsen * Avoid stacked headings Signed-off-by: Arve Knudsen --- contribute/style-guides/backend.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contribute/style-guides/backend.md b/contribute/style-guides/backend.md index 4d6e35df6d0..e83f0bd090a 100644 --- a/contribute/style-guides/backend.md +++ b/contribute/style-guides/backend.md @@ -75,3 +75,17 @@ Valid reasons to use a pointer include (but not necessarily limited to): allocating heap memory) * You might *need* `nil` to tell if a variable isn't set, although usually it's better to use the type's zero value to tell instead + +## Database + +In database related code, we follow certain patterns. + +### Foreign keys + +While they can be useful, we don't generally use foreign key constraints in Grafana, for historical and +technical reasons. See this [comment](https://github.com/grafana/grafana/issues/3269#issuecomment-383328548) by Torkel +for context. + +### Unique columns + +If a column, or column combination, should be unique, add a corresponding uniqueness constraint through a migration.