db: drop 10 unused legacy columns from packets table
Dead fields left over from the original parser schema: srccallsign, dstcallsign, origpacket, header, body, alive, posambiguity, symboltable, symbolcode, messaging. None are declared in the Packet schema, none are read anywhere in lib/ or test/, and Packet.strip_dead_fields/1 already removed them from attrs before insert. In environments where ConsolidatePacketsColumns (20260220230000) already DROP/RECREATEd the table without these columns the migration is a safety-net no-op thanks to IF EXISTS; otherwise it ALTERs the parent partitioned table and Postgres cascades to all partitions.
This commit is contained in:
parent
7cd9ccf2a0
commit
ead0be4434
1 changed files with 73 additions and 0 deletions
|
|
@ -0,0 +1,73 @@
|
|||
defmodule Aprsme.Repo.Migrations.DropUnusedPacketColumns do
|
||||
use Ecto.Migration
|
||||
|
||||
@moduledoc """
|
||||
Drops 10 legacy parser-compat columns from the partitioned `packets` table
|
||||
that are never read by any application code. Values are stripped from incoming
|
||||
attrs by `Aprsme.Packet.strip_dead_fields/1` before insert, so the columns
|
||||
have been write-only noise on the wire.
|
||||
|
||||
Each column is `ALTER TABLE ... DROP COLUMN IF EXISTS` on the parent
|
||||
partitioned table; PostgreSQL cascades the drop to every child partition.
|
||||
`IF EXISTS` keeps this migration idempotent against databases where the
|
||||
earlier `ConsolidatePacketsColumns` (20260220230000) DROP/RECREATE already
|
||||
removed these columns.
|
||||
|
||||
Columns dropped and rationale (one-liner each):
|
||||
|
||||
* `srccallsign` - duplicate of `sender`; never read.
|
||||
* `dstcallsign` - duplicate of `destination`; never read.
|
||||
* `origpacket` - duplicate of `raw_packet`; never read.
|
||||
* `header` - raw packet header bytes; never read after `raw_packet`
|
||||
superseded it.
|
||||
* `body` - raw packet body bytes; never read after `raw_packet`
|
||||
superseded it.
|
||||
* `alive` - legacy parser "liveness" flag (default 1); never read.
|
||||
* `posambiguity` - duplicate of `position_ambiguity`; never read (the
|
||||
canonical column lives in the `data` JSONB now).
|
||||
* `symboltable` - duplicate of `symbol_table_id`; never read.
|
||||
* `symbolcode` - duplicate of `symbol_code`; never read.
|
||||
* `messaging` - legacy int flag duplicating `aprs_messaging` (bool);
|
||||
never read.
|
||||
|
||||
The `down/0` recreates the columns with their original types from
|
||||
`PartitionPacketsTable` (20260220200000) so the migration is mechanically
|
||||
reversible — though column DATA is permanently lost on drop.
|
||||
"""
|
||||
|
||||
@dropped_columns [
|
||||
{:srccallsign, :varchar},
|
||||
{:dstcallsign, :varchar},
|
||||
{:origpacket, :text},
|
||||
{:header, :text},
|
||||
{:body, :text},
|
||||
{:alive, :integer, "DEFAULT 1"},
|
||||
{:posambiguity, :integer},
|
||||
{:symboltable, :varchar},
|
||||
{:symbolcode, :varchar},
|
||||
{:messaging, :integer}
|
||||
]
|
||||
|
||||
def up do
|
||||
execute("SET LOCAL statement_timeout = '0'")
|
||||
|
||||
for col <- @dropped_columns do
|
||||
name = elem(col, 0)
|
||||
execute("ALTER TABLE packets DROP COLUMN IF EXISTS #{name}")
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
execute("SET LOCAL statement_timeout = '0'")
|
||||
|
||||
for col <- @dropped_columns do
|
||||
{name, type, default} =
|
||||
case col do
|
||||
{n, t} -> {n, t, ""}
|
||||
{n, t, d} -> {n, t, " " <> d}
|
||||
end
|
||||
|
||||
execute("ALTER TABLE packets ADD COLUMN IF NOT EXISTS #{name} #{type}#{default}")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue