Skip to content

Commit

Permalink
feat: compute base content
Browse files Browse the repository at this point in the history
  • Loading branch information
lauti7 committed Oct 9, 2023
1 parent c65d7cc commit 7d0db2a
Show file tree
Hide file tree
Showing 2 changed files with 8,994 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/migrations/1696777096158_compute-places-with-categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/naming-convention */

import { ColumnDefinitions, MigrationBuilder } from "node-pg-migrate"

import PlaceCategories from "../entities/PlaceCategories/model"

export const shorthands: ColumnDefinitions | undefined = undefined

export async function up(pgm: MigrationBuilder): Promise<void> {
const { content } = await import("../seed/base_categorized_content.json")

let tmpRows = []
for (const row of content) {
if (row.category_id === "ads") continue
tmpRows.push(`('${row.place_id}', '${row.category_id}')`)

if (tmpRows.length === 100) {
pgm.sql(
`INSERT INTO ${
PlaceCategories.tableName
} (place_id, category_id) VALUES ${tmpRows.join(",")}`
)
tmpRows = []
}
}
}

export async function down(pgm: MigrationBuilder): Promise<void> {
const { content } = await import("../seed/base_categorized_content.json")

for (const row of content) {
if (row.category_id === "ads") continue

pgm.sql(
`DELETE FROM ${PlaceCategories.tableName} WHERE place_id = '${row.place_id}' AND category_id = '${row.category_id}'`
)
}
}
Loading

0 comments on commit 7d0db2a

Please sign in to comment.