Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding recurring donations and anchorContractAddress entities #1194

Merged
merged 12 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions migration/1702364570535-create_anchor_contract_address_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class createAnchorContractAddressTable1702364570535
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "anchor_contract_address" (
"id" SERIAL PRIMARY KEY,
"networkId" INTEGER NOT NULL,
"isActive" BOOLEAN DEFAULT false,
"address" TEXT NOT NULL,
"txHash" TEXT NOT NULL,
"projectId" INTEGER NULL,
"creatorId" INTEGER NULL,
"ownerId" INTEGER NULL,
"updatedAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "UQ_address_networkId_project" UNIQUE ("address", "networkId", "projectId")
);

CREATE INDEX "IDX_address" ON "anchor_contract_address" ("address");
CREATE INDEX "IDX_networkId" ON "anchor_contract_address" ("networkId");
CREATE INDEX "IDX_projectId" ON "anchor_contract_address" ("projectId");
CREATE INDEX "IDX_creatorId" ON "anchor_contract_address" ("creatorId");
CREATE INDEX "IDX_ownerId" ON "anchor_contract_address" ("ownerId");

`);

await queryRunner.query(`
ALTER TABLE "anchor_contract_address"
ADD CONSTRAINT "FK_anchor_contract_address_project"
FOREIGN KEY ("projectId") REFERENCES "project"("id")
ON DELETE SET NULL;
`);
}

async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "anchor_contract_address"
DROP CONSTRAINT "FK_anchor_contract_address_project";
`);

await queryRunner.query(`
DROP TABLE "anchor_contract_address";
`);
}
}
39 changes: 39 additions & 0 deletions migration/1702445735585-create_recurring_donation_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class createRecurringDonationTable1702445735585
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE recurring_donations (
id SERIAL PRIMARY KEY,
network_id INT NOT NULL,
tx_hash text NOT NULL,
project_id INT,
anchor_contract_address_id INT,
donor_id INT,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_project
FOREIGN KEY(project_id)
REFERENCES projects(id),
CONSTRAINT fk_anchor_contract_address
FOREIGN KEY(anchor_contract_address_id)
REFERENCES anchor_contract_addresses(id),
CONSTRAINT fk_donor
FOREIGN KEY(donor_id)
REFERENCES users(id),
UNIQUE(tx_hash, network_id, project_id)
);

CREATE INDEX idx_tx_hash ON recurring_donations(tx_hash);
CREATE INDEX idx_project_id ON recurring_donations(project_id);
CREATE INDEX idx_anchor_contract_address_id ON recurring_donations(anchor_contract_address_id);
CREATE INDEX idx_donor_id ON recurring_donations(donor_id);
`);
}

async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE IF EXISTS recurring_donations;`);
}
}
Loading
Loading