<p></p>
<p dir="auto">For historical reasons, we've ended up with quite a few database tables names that aren't aligned with the model names. I think in every case we prefer the model names (since these are easier to change, they tend to have been changed already without renaming the underlying table).</p>
<div class="highlight highlight-source-shell" dir="auto"><pre class="notranslate">andy@denali:<span class="pl-k">~</span>/src/openstreetmap-website$ grep -rn <span class="pl-s"><span class="pl-pds">'</span>self\.table_name<span class="pl-pds">'</span></span> app/models/
app/models/old_way.rb:24:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>ways<span class="pl-pds">"</span></span>
app/models/old_way_tag.rb:16:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>way_tags<span class="pl-pds">"</span></span>
app/models/way_tag.rb:15:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_way_tags<span class="pl-pds">"</span></span>
app/models/tracepoint.rb:26:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>gps_points<span class="pl-pds">"</span></span>
app/models/trace.rb:31:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>gpx_files<span class="pl-pds">"</span></span>
app/models/way_node.rb:20:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_way_nodes<span class="pl-pds">"</span></span>
app/models/relation_member.rb:21:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_relation_members<span class="pl-pds">"</span></span>
app/models/node.rb:31:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_nodes<span class="pl-pds">"</span></span>
app/models/way.rb:26:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_ways<span class="pl-pds">"</span></span>
app/models/old_way_node.rb:20:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>way_nodes<span class="pl-pds">"</span></span>
app/models/old_relation_tag.rb:16:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>relation_tags<span class="pl-pds">"</span></span>
app/models/old_relation.rb:24:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>relations<span class="pl-pds">"</span></span>
app/models/relation.rb:26:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_relations<span class="pl-pds">"</span></span>
app/models/old_relation_member.rb:22:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>relation_members<span class="pl-pds">"</span></span>
app/models/node_tag.rb:15:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_node_tags<span class="pl-pds">"</span></span>
app/models/old_node.rb:30:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>nodes<span class="pl-pds">"</span></span>
app/models/relation_tag.rb:15:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>current_relation_tags<span class="pl-pds">"</span></span>
app/models/follow.rb:22:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>friends<span class="pl-pds">"</span></span>
app/models/tracetag.rb:20:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>gpx_file_tags<span class="pl-pds">"</span></span>
app/models/old_node_tag.rb:16:  self.table_name = <span class="pl-s"><span class="pl-pds">"</span>node_tags<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">We might also want to rename certain tables that don't currently have a model, such as <code class="notranslate">changeset_subscribers</code> (to e.g. <code class="notranslate">changeset_subscriptions</code>) but I haven't made a list of these.</p>
<p dir="auto">Having these mismatched table/model names doesn't provide any benefits to anyone, as far as I can tell. It also makes it harder for new developers to get started, since they might look at the database structure (e.g. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2640712295" data-permission-text="Title is private" data-url="https://github.com/openstreetmap/openstreetmap-website/issues/5308" data-hovercard-type="pull_request" data-hovercard-url="/openstreetmap/openstreetmap-website/pull/5308/hovercard" href="https://github.com/openstreetmap/openstreetmap-website/pull/5308">#5308</a>) and then get confused when they can't find the corresponding models. In particular, I found it very confusing when I first started, since we have a table called "nodes" and a "Node" model, but these do not correspond with each other!</p>
<p dir="auto">So my proposal is to rename the tables to match the model names.</p>
<p dir="auto">There is a zero-downtime approach to renaming tables in PostgreSQL, as described at <a href="https://brandur.org/fragments/postgres-table-rename" rel="nofollow">https://brandur.org/fragments/postgres-table-rename</a> . In short, we</p>
<ul dir="auto">
<li>Rename the table, and create a view with the old name, in a transaction.</li>
<li>Update any code that accesses that table (e.g. rails, cgimap, replication utilities) to use the new table name directly.</li>
<li>Eventually, drop the view.</li>
</ul>
<p dir="auto">For a small number of renames, we will need to do this in multiple stages, due to conflicts (e.g. <code class="notranslate">nodes -> old_nodes</code> then <code class="notranslate">current_nodes -> nodes</code> some time later).</p>
<p dir="auto">Before getting started on this, my main question is whether the OSMF operations team (e.g. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tomhughes/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tomhughes">@tomhughes</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Firefishy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Firefishy">@Firefishy</a> ) see any problem with this, for example, any details about how the OSMF database replication works that would make this a non-starter. Or if there's any reasons that I haven't considered why this might not work.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/5619">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMY65ICH3HTREGQ2Z32OJFHFAVCNFSM6AAAAABWRVAF2WVHI2DSMVQWIX3LMV43ASLTON2WKOZSHAZTGNJYGYYDINY">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLIBLODFPZQWSDSQC3D2OJFHFA5CNFSM6AAAAABWRVAF2WWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHKRZIXP4.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/issues/5619</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/5619",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/5619",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>