-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCreateGistsTable.ts
More file actions
46 lines (40 loc) · 1.65 KB
/
Copy pathCreateGistsTable.ts
File metadata and controls
46 lines (40 loc) · 1.65 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
35
36
37
38
39
40
41
42
43
44
45
46
import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateGistsTable1700000000001 implements MigrationInterface {
name = 'CreateGistsTable1700000000001';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS "gists" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"content" TEXT NOT NULL,
"location_cell" VARCHAR(20),
"content_hash" VARCHAR(100),
"stellar_gist_id" VARCHAR(80),
"tx_hash" VARCHAR(80),
"location" geography(Point, 4326),
"created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT "PK_gists_id" PRIMARY KEY ("id")
)
`);
// B-tree index for cell-based lookups
await queryRunner.query(`
CREATE INDEX IF NOT EXISTS "idx_gists_location_cell"
ON "gists" ("location_cell")
`);
// GiST spatial index for ST_DWithin radius queries
await queryRunner.query(`
CREATE INDEX IF NOT EXISTS "idx_gists_location"
ON "gists" USING GIST ("location")
`);
// Cursor pagination index
await queryRunner.query(`
CREATE INDEX IF NOT EXISTS "idx_gists_created_at"
ON "gists" ("created_at" DESC)
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX IF EXISTS "idx_gists_created_at"`);
await queryRunner.query(`DROP INDEX IF EXISTS "idx_gists_location"`);
await queryRunner.query(`DROP INDEX IF EXISTS "idx_gists_location_cell"`);
await queryRunner.query(`DROP TABLE IF EXISTS "gists"`);
}
}