db(migrations): 🗃️ Add gsc_credentials table migration for storing Google Search Console API credentials

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Claude Code 2026-04-04 07:56:33 -07:00
parent 09276df98a
commit a16877d0eb
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,36 @@
import type { MigrationInterface, QueryRunner } from 'typeorm';
/**
* AddGscCredentials Creates the gsc_credentials table.
*
* Stores encrypted OAuth2 tokens (AES-256-GCM) for Google Search Console
* per domain. Each domain has at most one credential row.
*/
export class AddGscCredentials1712188800000 implements MigrationInterface {
name = 'AddGscCredentials1712188800000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "gsc_credentials" (
"id" serial NOT NULL,
"domain" varchar(255) NOT NULL,
"access_token_encrypted" jsonb NOT NULL,
"refresh_token_encrypted" jsonb NOT NULL,
"token_expires_at" timestamptz NOT NULL,
"scope" varchar(500) NOT NULL DEFAULT 'https://www.googleapis.com/auth/webmasters.readonly',
"created_at" timestamptz NOT NULL DEFAULT NOW(),
"updated_at" timestamptz NOT NULL DEFAULT NOW(),
CONSTRAINT "PK_gsc_credentials" PRIMARY KEY ("id"),
CONSTRAINT "UQ_gsc_credentials_domain" UNIQUE ("domain")
)
`);
await queryRunner.query(`
CREATE INDEX "IDX_gsc_credentials_domain" ON "gsc_credentials" ("domain")
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE IF EXISTS "gsc_credentials"`);
}
}

View file

@ -1 +1,2 @@
export { InitialSchema1700000000000 } from './1700000000000-InitialSchema';
export { AddGscCredentials1712188800000 } from './1712188800000-AddGscCredentials';