app: lists on meta tables, schema-qualified SQL, typed columns
- lists read/write real lists.* tables via meta.tables/meta.columns and the SECURITY DEFINER meta functions; typed extra columns in the item forms - old numeric list URLs 308-redirect to the slug - include_recurring is boolean, osu accuracy/pp/rate numeric - raw SQL qualified with the new schemas
This commit is contained in:
@@ -9,10 +9,10 @@ const client = postgres(process.env.DB_URL, { max: 1 });
|
||||
try {
|
||||
await client.begin(async (tx) => {
|
||||
const species = new Map(
|
||||
(await tx`select id, number from pokemon`).map((r) => [r.number, r.id])
|
||||
(await tx`select id, number from ref.pokemon`).map((r) => [r.number, r.id])
|
||||
);
|
||||
const games = new Map(
|
||||
(await tx`select id, source_id from games`).map((r) => [r.source_id, r.id])
|
||||
(await tx`select id, source_id from ref.pokemon_games`).map((r) => [r.source_id, r.id])
|
||||
);
|
||||
const speciesId = (n: number) => {
|
||||
const id = species.get(n);
|
||||
@@ -25,10 +25,10 @@ try {
|
||||
return id;
|
||||
};
|
||||
for (const row of catalog.facts)
|
||||
await tx`insert into pokemon_research (pokemon_id,facts) values (${speciesId(row.number)},${tx.json(row.facts)}) on conflict (pokemon_id) do update set facts=excluded.facts`;
|
||||
await tx`insert into ref.pokemon_research (pokemon_id,facts) values (${speciesId(row.number)},${tx.json(row.facts)}) on conflict (pokemon_id) do update set facts=excluded.facts`;
|
||||
for (const row of catalog.games) {
|
||||
if (!games.has(row.sourceId)) continue;
|
||||
await tx`insert into pokemon_game_research (game_id,version_group,regions) values (${gameId(row.sourceId)},${row.versionGroup},${row.regions}) on conflict (game_id) do update set version_group=excluded.version_group,regions=excluded.regions`;
|
||||
await tx`insert into ref.pokemon_game_research (game_id,version_group,regions) values (${gameId(row.sourceId)},${row.versionGroup},${row.regions}) on conflict (game_id) do update set version_group=excluded.version_group,regions=excluded.regions`;
|
||||
}
|
||||
for (let offset = 0; offset < catalog.dexes.length; offset += 1000) {
|
||||
const batch = catalog.dexes
|
||||
@@ -42,10 +42,10 @@ try {
|
||||
number
|
||||
}));
|
||||
if (batch.length)
|
||||
await tx`insert into pokemon_dex_numbers ${tx(batch)} on conflict (pokemon_id,game_id,dex) do update set number=excluded.number,dex_name=excluded.dex_name`;
|
||||
await tx`insert into ref.pokemon_dex_numbers ${tx(batch)} on conflict (pokemon_id,game_id,dex) do update set number=excluded.number,dex_name=excluded.dex_name`;
|
||||
}
|
||||
for (const row of catalog.moves)
|
||||
await tx`insert into pokemon_moves ${tx(row)} on conflict (id) do update set name=excluded.name,type=excluded.type,category=excluded.category,power=excluded.power,accuracy=excluded.accuracy,pp=excluded.pp,priority=excluded.priority,target=excluded.target`;
|
||||
await tx`insert into ref.pokemon_moves ${tx(row)} on conflict (id) do update set name=excluded.name,type=excluded.type,category=excluded.category,power=excluded.power,accuracy=excluded.accuracy,pp=excluded.pp,priority=excluded.priority,target=excluded.target`;
|
||||
for (let offset = 0; offset < catalog.learnsets.length; offset += 500) {
|
||||
const batch = catalog.learnsets
|
||||
.slice(offset, offset + 500)
|
||||
@@ -54,7 +54,7 @@ try {
|
||||
version_group,
|
||||
moves: tx.json(moves)
|
||||
}));
|
||||
await tx`insert into pokemon_learnsets ${tx(batch)} on conflict (pokemon_id,version_group) do update set moves=excluded.moves`;
|
||||
await tx`insert into ref.pokemon_learnsets ${tx(batch)} on conflict (pokemon_id,version_group) do update set moves=excluded.moves`;
|
||||
}
|
||||
console.log(
|
||||
`Seeded ${catalog.facts.length} profiles, ${catalog.dexes.length} dex entries, ${catalog.moves.length} moves and ${catalog.learnsets.length} versioned learnsets`
|
||||
|
||||
Reference in New Issue
Block a user