-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: rename updates table * chore: add project id column to updates table
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { MigrationBuilder } from "node-pg-migrate" | ||
|
||
export async function up(pgm: MigrationBuilder): Promise<void> { | ||
pgm.renameTable('proposal_updates', 'project_updates') | ||
} | ||
|
||
export async function down(pgm: MigrationBuilder): Promise<void> { | ||
pgm.renameTable('project_updates', 'proposal_updates') | ||
} |
30 changes: 30 additions & 0 deletions
30
src/migrations/1717082952079_add-project-id-column-to-updates-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { MigrationBuilder } from "node-pg-migrate" | ||
import UpdateModel from "../entities/Updates/model" | ||
import ProjectModel from "../back/models/Project" | ||
|
||
export async function up(pgm: MigrationBuilder): Promise<void> { | ||
pgm.addColumn(UpdateModel.tableName, { | ||
project_id: { | ||
type: 'TEXT', | ||
notNull: false, | ||
}, | ||
}) | ||
pgm.addConstraint(UpdateModel.tableName, 'fk_project_id', { | ||
foreignKeys: { | ||
columns: ['project_id'], | ||
references: `${ProjectModel.tableName}(id)`, | ||
}, | ||
}) | ||
const query = ` | ||
UPDATE ${UpdateModel.tableName} | ||
SET project_id = p.id | ||
FROM ${ProjectModel.tableName} p | ||
WHERE ${UpdateModel.tableName}.proposal_id = p.proposal_id | ||
` | ||
pgm.sql(query) | ||
} | ||
|
||
export async function down(pgm: MigrationBuilder): Promise<void> { | ||
pgm.dropConstraint(UpdateModel.tableName, 'fk_project_id', {ifExists: true}) | ||
pgm.dropColumn(UpdateModel.tableName, 'project_id') | ||
} |