Skip to content

Commit b4388a4

Browse files
committed
derive backfilled_tables from schema_mappings
1 parent 2f86af7 commit b4388a4

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

scripts/database_migration.exs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@ defmodule DatabaseMigration do
5959
{"StripePaymentMethod", PaymentMethod}
6060
]
6161

62-
@backfilled_tables [
63-
"accounts",
64-
"payment_methods",
65-
"customers",
66-
"installations",
67-
"repositories",
68-
"transactions",
69-
"claims",
70-
"attempts",
71-
"bounties",
72-
"tips",
73-
"tickets",
74-
"members",
75-
"identities",
76-
"users"
77-
]
78-
7962
@index_fields [
8063
{"GithubUser", ["id", "user_id"]},
8164
{"User", ["id"]},
@@ -90,7 +73,20 @@ defmodule DatabaseMigration do
9073
{"Reward", ["bounty_id"]}
9174
]
9275

93-
defp relevant_tables, do: @schema_mappings |> Enum.map(fn {k, _v} -> k end) |> Enum.dedup()
76+
defp relevant_tables do
77+
@schema_mappings
78+
|> Enum.map(fn {k, _v} -> k end)
79+
|> Enum.dedup()
80+
end
81+
82+
defp backfilled_tables do
83+
@schema_mappings
84+
|> Enum.map(fn {_, v} -> v end)
85+
|> Enum.reject(&is_nil/1)
86+
|> Enum.dedup()
87+
|> Enum.reverse()
88+
|> Enum.map(& &1.__schema__(:source))
89+
end
9490

9591
defp transform({"Task", Ticket}, row, db) do
9692
if row["forge"] != "github" do
@@ -1098,7 +1094,7 @@ defmodule DatabaseMigration do
10981094
[
10991095
"BEGIN TRANSACTION;",
11001096
"SET CONSTRAINTS ALL DEFERRED;",
1101-
Enum.map(@backfilled_tables, &"TRUNCATE TABLE #{&1} CASCADE;"),
1097+
Enum.map(backfilled_tables(), &"TRUNCATE TABLE #{&1} CASCADE;"),
11021098
"SET CONSTRAINTS ALL IMMEDIATE;",
11031099
"COMMIT;"
11041100
]

0 commit comments

Comments
 (0)