Skip to content

Commit 2fdc372

Browse files
narrowizardclaude
andcommitted
refactor(migrations): remove PostgreSQL extensions (citext, pgcrypto, uuid-ossp)
- Replace pgcrypto/uuid-ossp with custom gen_random_uuid() SQL function - Disable citext extension (replaced with VARCHAR + application-layer handling) - Change account.name, account.email, api_key.name from citext to VARCHAR 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3657ae9 commit 2fdc372

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

api/src/data_sources/migrations/1653356327062-init-db.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
22

33
export class initDb1653356327062 implements MigrationInterface {
44
public async up(queryRunner: QueryRunner): Promise<void> {
5-
await queryRunner.query('CREATE EXTENSION IF NOT EXISTS "pgcrypto"');
6-
await queryRunner.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"');
5+
await queryRunner.query(`
6+
CREATE OR REPLACE FUNCTION public.gen_random_uuid()
7+
RETURNS uuid
8+
LANGUAGE sql
9+
PARALLEL SAFE
10+
AS $$
11+
SELECT cast(
12+
lpad(to_hex(floor(random() * 4294967296)::bigint), 8, '0') || '-' ||
13+
lpad(to_hex(floor(random() * 65536)::int), 4, '0') || '-' ||
14+
'4' || lpad(to_hex(floor(random() * 4096)::int), 3, '0') || '-' ||
15+
substr('89ab', (floor(random() * 4) + 1)::int, 1) ||
16+
lpad(to_hex(floor(random() * 4096)::int), 3, '0') || '-' ||
17+
lpad(to_hex(floor(random() * 281474976710656)::bigint), 12, '0')
18+
AS uuid);
19+
$$;
20+
`);
721
await queryRunner.query(`
822
CREATE OR REPLACE FUNCTION trigger_set_update_time() RETURNS TRIGGER AS $$
923
BEGIN
@@ -16,7 +30,6 @@ export class initDb1653356327062 implements MigrationInterface {
1630

1731
public async down(queryRunner: QueryRunner): Promise<void> {
1832
await queryRunner.query(`DROP FUNCTION IF EXISTS trigger_set_update_time()`);
19-
await queryRunner.query(`DROP EXTENSION IF EXISTS "pgcrypto"`);
20-
await queryRunner.query(`DROP EXTENSION IF EXISTS "uuid-ossp"`);
33+
await queryRunner.query(`DROP FUNCTION IF EXISTS public.gen_random_uuid()`);
2134
}
2235
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { MigrationInterface, QueryRunner } from 'typeorm';
22

3+
// Migration disabled - citext extension no longer needed
34
export class addExtensionCitext1660005273691 implements MigrationInterface {
4-
public async up(queryRunner: QueryRunner): Promise<void> {
5-
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS citext`);
5+
public async up(): Promise<void> {
6+
// No-op: citext extension removed
67
}
78

8-
public async down(queryRunner: QueryRunner): Promise<void> {
9-
await queryRunner.query(`DROP EXTENSION IF EXISTS citext`);
9+
public async down(): Promise<void> {
10+
// No-op
1011
}
1112
}

api/src/data_sources/migrations/1660005298185-create-users-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export class createUsersTable1660005298185 implements MigrationInterface {
66
`CREATE TABLE account
77
(
88
id uuid NOT NULL DEFAULT gen_random_uuid(),
9-
name citext NOT NULL,
10-
email citext DEFAULT NULL,
9+
name VARCHAR NOT NULL,
10+
email VARCHAR DEFAULT NULL,
1111
password VARCHAR NOT NULL,
1212
role_id SMALLINT NOT NULL DEFAULT 10,
1313
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,

api/src/data_sources/migrations/1667183651604-create-api_keys-table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class createApiKeysTable1667183651604 implements MigrationInterface {
66
`CREATE TABLE api_key
77
(
88
id uuid NOT NULL DEFAULT gen_random_uuid(),
9-
name citext NOT NULL,
9+
name VARCHAR NOT NULL,
1010
key VARCHAR NOT NULL,
1111
domain VARCHAR NOT NULL,
1212
role_id SMALLINT NOT NULL DEFAULT 10,

0 commit comments

Comments
 (0)