@sphereon/ssi-sdk.data-store
Version:
80 lines • 4.29 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixCredentialClaimsReferencesUuidSqlite1741895822987 = void 0;
class FixCredentialClaimsReferencesUuidSqlite1741895822987 {
constructor() {
this.name = 'FixCredentialClaimsReferencesUuid1741895822987';
}
up(queryRunner) {
return __awaiter(this, void 0, void 0, function* () {
// Create a new table with the updated column type (uuid)
yield queryRunner.query(`
CREATE TABLE "CredentialClaims_new"
(
"id" uuid NOT NULL DEFAULT (lower(hex(randomblob(16)))),
"key" character varying(255) NOT NULL,
"name" character varying(255) NOT NULL,
"credentialLocaleBrandingId" uuid,
CONSTRAINT "PK_CredentialClaims_id" PRIMARY KEY ("id")
)
`);
// Copy data from the old table
yield queryRunner.query(`
INSERT INTO "CredentialClaims_new" ("id", "key", "name", "credentialLocaleBrandingId")
SELECT "id", "key", "name", "credentialLocaleBrandingId"
FROM "CredentialClaims"
`);
// Drop the old table
yield queryRunner.query(`DROP TABLE "CredentialClaims"`);
// Rename the new table to the original name
yield queryRunner.query(`ALTER TABLE "CredentialClaims_new" RENAME TO "CredentialClaims"`);
// Recreate the unique index
yield queryRunner.query(`
CREATE UNIQUE INDEX "IDX_CredentialClaimsEntity_credentialLocaleBranding_locale"
ON "CredentialClaims" ("credentialLocaleBrandingId", "key")
`);
});
}
down(queryRunner) {
return __awaiter(this, void 0, void 0, function* () {
// Migrate uuid back to varchar
// Create a new table reverting the column back to character varying
yield queryRunner.query(`
CREATE TABLE "CredentialClaims_old"
(
"id" uuid NOT NULL DEFAULT (lower(hex(randomblob(16)))),
"key" character varying(255) NOT NULL,
"name" character varying(255) NOT NULL,
"credentialLocaleBrandingId" character varying,
CONSTRAINT "PK_CredentialClaims_id" PRIMARY KEY ("id")
)
`);
// Copy data from the current table
yield queryRunner.query(`
INSERT INTO "CredentialClaims_old" ("id", "key", "name", "credentialLocaleBrandingId")
SELECT "id", "key", "name", "credentialLocaleBrandingId"
FROM "CredentialClaims"
`);
// Drop the current table
yield queryRunner.query(`DROP TABLE "CredentialClaims"`);
// Rename the new table back to the original name
yield queryRunner.query(`ALTER TABLE "CredentialClaims_old" RENAME TO "CredentialClaims"`);
// Recreate the unique index
yield queryRunner.query(`
CREATE UNIQUE INDEX "IDX_CredentialClaimsEntity_credentialLocaleBranding_locale"
ON "CredentialClaims" ("credentialLocaleBrandingId", "key")
`);
});
}
}
exports.FixCredentialClaimsReferencesUuidSqlite1741895822987 = FixCredentialClaimsReferencesUuidSqlite1741895822987;
//# sourceMappingURL=1741895822987-FixCredentialClaimsReferencesUuid.js.map