Skip to content

Commit 1703c7b

Browse files
Merge pull request #796 from decentraland/fix/migration-content-ratings
fix: Content rating migration
2 parents 96cfd6f + 5d39cad commit 1703c7b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/migrations/1770729788000_rename-place-id-to-entity-id.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { ColumnDefinitions, MigrationBuilder } from "node-pg-migrate"
33
export const shorthands: ColumnDefinitions | undefined = undefined
44

55
export async function up(pgm: MigrationBuilder): Promise<void> {
6+
// Rename place_content_ratings table to content_ratings if it still has the old name.
7+
// On existing databases the table was created as "place_content_ratings";
8+
// on fresh databases the table is already "content_ratings" (model.tableName changed).
9+
pgm.sql(
10+
`ALTER TABLE IF EXISTS "place_content_ratings" RENAME TO "content_ratings"`
11+
)
12+
613
// Rename place_id to entity_id in user_favorites table
714
pgm.renameColumn("user_favorites", "place_id", "entity_id")
815

@@ -22,4 +29,9 @@ export async function down(pgm: MigrationBuilder): Promise<void> {
2229

2330
// Revert: rename entity_id back to place_id in content_ratings table
2431
pgm.renameColumn("content_ratings", "entity_id", "place_id")
32+
33+
// Revert the table rename back to place_content_ratings
34+
pgm.sql(
35+
`ALTER TABLE IF EXISTS "content_ratings" RENAME TO "place_content_ratings"`
36+
)
2537
}

0 commit comments

Comments
 (0)