Skip to content

Commit decfb3f

Browse files
committed
chore: automatic integrations table backups
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent 4503739 commit decfb3f

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

backend/src/database/migrations/U1762773409__integrations-backup.sql

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create table "integrationsHistory" as
2+
select *
3+
from "integrations"
4+
where 1 = 2;
5+
6+
alter table "integrationsHistory"
7+
add column "historyCreatedAt" timestamptz not null default now();
8+
9+
create index if not exists ix_integration_history_integration_id on "integrationsHistory" ("id");
10+
create index if not exists ix_integration_history_history_created_at on "integrationsHistory" ("historyCreatedAt");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import CronTime from 'cron-time-generator'
2+
3+
import { IS_PROD_ENV } from '@crowd/common'
4+
import { WRITE_DB_CONFIG, getDbConnection } from '@crowd/data-access-layer/src/database'
5+
6+
import { IJobDefinition } from '../types'
7+
8+
const job: IJobDefinition = {
9+
name: 'integrations-backup',
10+
cronTime: CronTime.every(1).minutes(),
11+
timeout: 60 * 60, // 1 hour = 60 * 60 seconds
12+
enabled: async () => true,
13+
process: async (ctx) => {
14+
ctx.log.info('Starting integrations backup job!')
15+
const dbConnection = await getDbConnection(WRITE_DB_CONFIG(), 1, 0)
16+
await dbConnection.query(`insert into "integrationsHistory" select * from "integrations";`)
17+
ctx.log.info('Integrations backup job completed!')
18+
},
19+
}
20+
21+
export default job

0 commit comments

Comments
 (0)