-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
20 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
api/apps/api/src/migrations/api/1632999358910-AddTimestampToJobStatusView.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,61 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddTimestampToJobStatusView1632999358910 | ||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP VIEW "scenario_job_status"; | ||
`); | ||
await queryRunner.query(` | ||
CREATE VIEW "scenario_job_status" AS | ||
SELECT | ||
DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS scenario_id, | ||
projects.id AS project_id, | ||
api_events.kind, | ||
api_events.data, | ||
api_events.timestamp | ||
FROM | ||
api_events | ||
INNER JOIN scenarios ON api_events.topic = scenarios.id | ||
INNER JOIN projects ON projects.id = scenarios.project_id | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'scenario.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY | ||
job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP VIEW "scenario_job_status"; | ||
`); | ||
await queryRunner.query(` | ||
CREATE VIEW "scenario_job_status" AS | ||
SELECT | ||
DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS scenario_id, | ||
projects.id AS project_id, | ||
api_events.kind, | ||
api_events.data | ||
FROM | ||
api_events | ||
INNER JOIN scenarios ON api_events.topic = scenarios.id | ||
INNER JOIN projects ON projects.id = scenarios.project_id | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'scenario.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY | ||
job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC; | ||
`); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
api/apps/api/src/migrations/api/1632999473857-AddTimestampToProjectJobsStatus.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,50 @@ | ||
import { QueryRunner } from 'typeorm'; | ||
|
||
export class AddTimestampToProjectJobsStatus1632999473857 { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP VIEW "project_job_status"; | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE VIEW "project_job_status" as | ||
SELECT DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS project_id, | ||
api_events.kind, | ||
api_events.data, | ||
api_events.timestamp | ||
FROM api_events | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'project.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP VIEW "project_job_status"; | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE VIEW "project_job_status" as | ||
SELECT DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS project_id, | ||
api_events.kind, | ||
api_events.data | ||
FROM api_events | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'project.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC; | ||
`); | ||
} | ||
} |
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
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
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