Skip to content

Commit

Permalink
Size increase for namespace column (#2639)
Browse files Browse the repository at this point in the history
* Increase size of namespace column

* MariaDB migration

* MySQL migration

* MSSQL migration

* Postgres migration

* Planetscale migration

* fixed indexNamespace

* Paginate

---------

Co-authored-by: Deepak Prabhakara <[email protected]>
  • Loading branch information
niwsa and deepakprabhakara authored May 21, 2024
1 parent a30efd8 commit 25b29d7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 16 deletions.
14 changes: 14 additions & 0 deletions npm/migration/mariadb/1714417013715-md_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MdNamespace1714417013715 implements MigrationInterface {
name = 'MdNamespace1714417013715'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(256) NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(64) NULL`);
}

}
14 changes: 14 additions & 0 deletions npm/migration/mssql/1714421718208-mss_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MssNamespace1714421718208 implements MigrationInterface {
name = 'MssNamespace1714421718208'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jackson_store" ALTER COLUMN "namespace" varchar(256)`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jackson_store" ALTER COLUMN "namespace" varchar(64)`);
}

}
14 changes: 14 additions & 0 deletions npm/migration/mysql/1714419315556-ms_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MsNamespace1714419315556 implements MigrationInterface {
name = 'MsNamespace1714419315556'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(256) NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(64) NULL`);
}

}
14 changes: 14 additions & 0 deletions npm/migration/planetscale/1714457285484-ms_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MsNamespace1714457285484 implements MigrationInterface {
name = 'MsNamespace1714457285484'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(256) NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`jackson_store\` MODIFY \`namespace\` varchar(64) NULL`);
}

}
14 changes: 14 additions & 0 deletions npm/migration/postgres/1714452929542-pg_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class PgNamespace1714452929542 implements MigrationInterface {
name = 'PgNamespace1714452929542'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jackson_store" ALTER COLUMN "namespace" TYPE VARCHAR(256)`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "jackson_store" ALTER COLUMN "namespace" TYPE VARCHAR(64)`);
}

}
2 changes: 1 addition & 1 deletion npm/src/db/planetscale/entity/JacksonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class JacksonStore {
@Index('_jackson_store_namespace')
@Column({
type: 'varchar',
length: 64,
length: 256,
nullable: true,
})
namespace?: string;
Expand Down
2 changes: 1 addition & 1 deletion npm/src/db/sql/entity/JacksonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class JacksonStore {
@Index('_jackson_store_namespace')
@Column({
type: 'varchar',
length: 64,
length: 256,
nullable: true,
})
namespace?: string;
Expand Down
2 changes: 1 addition & 1 deletion npm/src/db/sql/mariadb/entity/JacksonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class JacksonStore {
@Index('_jackson_store_namespace')
@Column({
type: 'varchar',
length: 64,
length: 256,
nullable: true,
})
namespace?: string;
Expand Down
2 changes: 1 addition & 1 deletion npm/src/db/sql/mssql/entity/JacksonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class JacksonStore {
@Index('_jackson_store_namespace')
@Column({
type: 'varchar',
length: 64,
length: 256,
nullable: true,
})
namespace?: string;
Expand Down
35 changes: 23 additions & 12 deletions npm/src/db/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,30 @@ class Sql implements DatabaseDriver {
}

async indexNamespace() {
const res = await this.storeRepository.find({
where: {
namespace: IsNull(),
},
select: ['key'],
});
const searchTerm = ':';
try {
const take = 1000;
while (true) {
const res = await this.storeRepository.find({
where: {
namespace: IsNull(),
},
select: ['key'],
take,
});
const searchTerm = ':';

for (const r of res) {
const key = r.key;
const tokens2 = key.split(searchTerm).slice(0, 2);
const value = tokens2.join(searchTerm);
await this.storeRepository.update({ key }, { namespace: value });
if (res.length === 0) {
break;
}

for (const r of res) {
const key = r.key;
const lastIndex = r.key.lastIndexOf(searchTerm);
await this.storeRepository.update({ key }, { namespace: r.key.substring(0, lastIndex) });
}
}
} catch (err) {
console.error('Error running indexNamespace:', err);
}
}

Expand Down

0 comments on commit 25b29d7

Please sign in to comment.