Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Feb 26, 2024
1 parent ad4e9a9 commit 5e323e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

import defaultPermissions from '../../../../helpers/permissions/defaultPermissions.js';
import { insertItemIntoTable } from '../../../insertItemIntoTable.js';

export class permissionScopes1678892044040 implements MigrationInterface {
name = 'permissionScopes1678892044040';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = await queryRunner.query(`SELECT * FROM \`permissions\``);
await queryRunner.query(`DROP TABLE \`permissions\``);
await queryRunner.query(`CREATE TABLE \`permissions\` (\`id\` varchar(36) NOT NULL, \`name\` varchar(255) NOT NULL, \`order\` int NOT NULL, \`isCorePermission\` tinyint NOT NULL, \`isWaterfallAllowed\` tinyint NOT NULL, \`automation\` varchar(12) NOT NULL, \`userIds\` text NOT NULL, \`excludeUserIds\` text NOT NULL, \`filters\` json NOT NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`permissions\` ADD \`haveAllScopes\` tinyint NOT NULL DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`permissions\` ADD \`scopes\` text NOT NULL`);
await queryRunner.query(`UPDATE \`permissions\` SET \`haveAllScopes\` = 1 WHERE \`id\` != ?`, [defaultPermissions.CASTERS]);
for (const item of items) {
item.scopes = '[]';
item.haveAllScopes = item.id === defaultPermissions.CASTERS;
await insertItemIntoTable('permissions', item, queryRunner);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

import defaultPermissions from '../../../../helpers/permissions/defaultPermissions.js';
import { insertItemIntoTable } from '../../../insertItemIntoTable.js';

export class permissionScopes1678892044040 implements MigrationInterface {
name = 'permissionScopes1678892044040';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = await queryRunner.query(`SELECT * FROM "permissions"`);
await queryRunner.query(`DROP TABLE "permissions"`);
await queryRunner.query(`CREATE TABLE "permissions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "order" integer NOT NULL, "isCorePermission" boolean NOT NULL, "isWaterfallAllowed" boolean NOT NULL, "automation" character varying(12) NOT NULL, "userIds" text NOT NULL, "excludeUserIds" text NOT NULL, "filters" json NOT NULL, CONSTRAINT "PK_920331560282b8bd21bb02290df" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "permissions" ADD "haveAllScopes" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`ALTER TABLE "permissions" ADD "scopes" text NOT NULL`);
await queryRunner.query('UPDATE "permissions" SET "haveAllScopes" = true WHERE "id" != $1', [defaultPermissions.CASTERS]);
for (const item of items) {
item.scopes = '[]';
item.haveAllScopes = item.id === defaultPermissions.CASTERS;
await insertItemIntoTable('permissions', item, queryRunner);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class permissionScopes1678892044040 implements MigrationInterface {
await queryRunner.query(`CREATE TABLE "permissions" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "order" integer NOT NULL, "isCorePermission" boolean NOT NULL, "isWaterfallAllowed" boolean NOT NULL, "automation" varchar(12) NOT NULL, "userIds" text NOT NULL, "excludeUserIds" text NOT NULL, "filters" text NOT NULL, "haveAllScopes" boolean NOT NULL DEFAULT (0), "scopes" text NOT NULL)`);

for (const item of items) {
item.scopes = [];
item.scopes = '[]';
item.haveAllScopes = item.id === defaultPermissions.CASTERS;
await insertItemIntoTable('permissions', item, queryRunner);
}
Expand Down

0 comments on commit 5e323e8

Please sign in to comment.