forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20260101000000-create-campaigns-table.ts
More file actions
34 lines (31 loc) · 1.33 KB
/
Copy path20260101000000-create-campaigns-table.ts
File metadata and controls
34 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateCampaignsTable20260101000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS campaigns (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
merchant_id UUID NOT NULL REFERENCES merchants(id) ON DELETE CASCADE,
status VARCHAR(50) NOT NULL DEFAULT 'draft',
reward_amount DECIMAL(20,7) NOT NULL,
total_budget DECIMAL(20,7) NOT NULL,
remaining_budget DECIMAL(20,7) NOT NULL,
start_date TIMESTAMP NOT NULL,
end_date TIMESTAMP NOT NULL,
max_claims INT,
total_claims INT NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
`);
await queryRunner.query(`
CREATE INDEX idx_campaigns_status_created ON campaigns(status, created_at);
CREATE INDEX idx_campaigns_merchant_status ON campaigns(merchant_id, status);
CREATE INDEX idx_campaigns_dates ON campaigns(start_date, end_date);
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE IF EXISTS campaigns`);
}
}