Skip to content

Commit 211ee58

Browse files
authored
Merge pull request #226 from alphagov/add-adr-mobility-table-backend
Add ADR for using Mobility's table backend
2 parents 9eb96e4 + f12600b commit 211ee58

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

ADR/ADR043-use-mobility-with-column-strategy.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Date: 2025-06-09
44

55
## Status
66

7-
Accepted
7+
Superseded by [ADR046: Use Mobility's table backend strategy to store translations](ADR046-use-mobility-table-backend-strategy.md).
88

99
## Context
1010

@@ -28,58 +28,74 @@ The main strategies for storing translations are:
2828
- essentially a variant of the serialized data strategy that takes advantage of PostgreSQL's jsonb column type to make data easier to query.
2929

3030
#### Translatable columns
31+
3132
Advantages:
33+
3234
- Simple to understand and work with
3335
- Easy to query
3436

3537
Disadvantages:
38+
3639
- Since new columns need to be added to every table for every language, the maintenance burden increases as the number of locales increases
3740
- Since every new model would require new columns, maintenance burden increases as number of models increases
3841
- Inefficient use of database space
3942

4043
We currently have a small number of models and locales which mitigates the main disadvantages, so this seems like a good option for us.
4144

4245
#### Model translation tables
46+
4347
Advantages:
48+
4449
- Scales well with locales (since all locales can use the same table)
4550
- Uses space more efficiently than translatable columns
4651

4752
Disadvantages:
53+
4854
- Adds one extra table per model, so maintenance burden increases as the number of models increases
4955
- Requires table joins, creating increased complexity and risk of performance issues
5056

5157
This could be a good option for us, since we have a small number of models.
5258

5359
#### Shared translation tables
60+
5461
Advantages
62+
5563
- Versatile, no additional migrations required when adding new locales or models
5664

5765
Disadvantages
66+
5867
- Requires more complex table joins, creating increased complexity and risk of performance issues
5968
- since tables don't map 1:1 with model tables, it's harder to keep the shared table up to date with attribute renames and dropped columns
6069

6170
This could work for for us, but might be needlessly complex for the number of models and locales we're currently expecting to have.
6271

6372
#### Serialized data
73+
6474
Advantages:
75+
6576
- Simple to understand and work with
6677

6778
Disavantages:
79+
6880
- Difficult to add constraints
6981
- Difficult to query
7082

71-
We recommend against this option - the PostgreSQl jsonb strategy is functionally similar with fewer disadvantages.
83+
We recommend against this option - the PostgreSQl jsonb strategy is functionally similar with fewer disadvantages.
7284

7385
#### PostgreSQL jsonb
86+
7487
Advantages:
88+
7589
- Simple to understand and work with
7690

7791
Disavantages:
92+
7893
- Difficult to add constraints
7994

8095
We think the inability to easily add database constraints makes this a poor option for our use case.
8196

8297
### Gems
98+
8399
There are a few popular Ruby gems for dealing with translations. We looked into:
84100

85101
- [Mobility](https://github.com/shioyama/mobility)
@@ -92,6 +108,7 @@ Of these, only Mobility and Globalize have received recent updates. Mobility is
92108
Mobility also supports all of the backend strategies we've looked at, with largely the same API for each, which means it would be helpful if we decided we wanted to change strategy later.
93109

94110
We also considered the possibility of implementing our own solution without using a gem. In this case we’d:
111+
95112
- Have one less dependency
96113
- Have more control over our implementation
97114
- Have to manage database changes manually
@@ -101,6 +118,7 @@ We also considered the possibility of implementing our own solution without usin
101118
## Decision
102119

103120
We have decided to:
121+
104122
- implement translatable columns for each translatable text field
105123
- use the Mobility gem, configured with the `:column` backend strategy, to manage this
106124

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ADR046: Use Mobility's table backend strategy to store translations
2+
3+
Date: 2025-09-08
4+
5+
## Status
6+
7+
Accepted
8+
9+
## Context
10+
11+
We previously decided in [ADR043: Use Mobility gem with :column strategy to manage translated fields](ADR043-use-mobility-with-column-strategy.md) that we would use Mobility's column strategy to handle storing translations.
12+
13+
Our initial proposal was to use the column strategy (the simplest strategy Mobility supports) while we had a small number of languages (English and Welsh), and reassess later whether to use a more elaborate strategy if we add more languages. We concluded that Mobility's table strategy (described as 'Model translation tables' in the earlier ADR) scales better with an increased number of languages, so this is likely to be a better option than the column strategy if we need to support more than a few languages.
14+
15+
In conversations with departments we have found that there is demand for supporting additional languages, so we think we are likely to need the more scalable backend strategy.
16+
17+
Rather than implement the column strategy initially and migrate to the table strategy later, it would be less work to implement the table strategy directly.
18+
19+
## Decision
20+
21+
We have decided to:
22+
23+
- implement translation tables for each model
24+
- use the Mobility gem, configured with the `:table` backend strategy, to manage this
25+
26+
## Consequences
27+
28+
- adding additional languages in future should be easier
29+
- when adding new models, we will need to add a translation table for each new model

0 commit comments

Comments
 (0)