Rename "Pad" to "Map" in HistoryEntry.type

v5
Candid Dauth 2024-04-22 16:45:30 +02:00
rodzic 7a5d74dc74
commit b2bbe1c2a2
6 zmienionych plików z 27 dodań i 7 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ export interface HistoryEntryLabels {
export function getLabelsForHistoryEntry(client: ClientContext, entry: HistoryEntry): HistoryEntryLabels {
const i18n = getI18n();
if(entry.type == "Pad") {
if(entry.type == "Map") {
return {
description: i18n.t("history-utils.description-update-map"),
revert: {

Wyświetl plik

@ -31,7 +31,7 @@ export default class DatabaseHistory {
this.HistoryModel.init({
id: getDefaultIdType(),
time: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
type: { type: DataTypes.ENUM("Marker", "Line", "View", "Type", "Pad"), allowNull: false },
type: { type: DataTypes.ENUM("Marker", "Line", "View", "Type", "Map"), allowNull: false },
action: { type: DataTypes.ENUM("create", "update", "delete"), allowNull: false },
objectId: { type: DataTypes.INTEGER(), allowNull: true }, // Is null when type is pad
objectBefore: {
@ -79,7 +79,7 @@ export default class DatabaseHistory {
})).map(it => it.id);
const dataClone = cloneDeep(data);
if(data.type != "Pad") {
if(data.type != "Map") {
if(dataClone.objectBefore) {
delete (dataClone.objectBefore as any).id;
delete (dataClone.objectBefore as any).padId;
@ -117,7 +117,7 @@ export default class DatabaseHistory {
async revertHistoryEntry(mapId: MapId, id: ID): Promise<void> {
const entry = await this.getHistoryEntry(mapId, id);
if(entry.type == "Pad") {
if(entry.type == "Map") {
if (!entry.objectBefore) {
throw new Error(getI18n().t("database.old-map-data-not-available-error"));
}

Wyświetl plik

@ -139,7 +139,7 @@ export default class DatabaseMaps {
throw new Error(getI18n().t("database.map-disappeared-error"));
await this._db.history.addHistoryEntry(data.id || mapId, {
type: "Pad",
type: "Map",
action: "update",
objectBefore: oldData,
objectAfter: newData

Wyświetl plik

@ -18,6 +18,7 @@ export interface MetaProperties {
typesIdxMigrationCompleted: "1";
viewsIdxMigrationCompleted: "1";
fieldIconsMigrationCompleted: "1";
historyPadMigrationCompleted: "1";
}
export default class DatabaseMeta {

Wyświetl plik

@ -35,6 +35,7 @@ export default class DatabaseMigrations {
await this._typesIdxMigration();
await this._viewsIdxMigration();
await this._fieldIconsMigration();
await this._historyPadMigration();
(async () => {
await this._elevationMigration();
@ -722,4 +723,22 @@ export default class DatabaseMigrations {
await this._db.meta.setMeta("fieldIconsMigrationCompleted", "1");
}
/** Rename Pad to Map in History.type */
async _historyPadMigration(): Promise<void> {
if(await this._db.meta.getMeta("historyPadMigrationCompleted") == "1")
return;
console.log("DB migration: Rename Pad to Map in History.type");
const queryInterface = this._db._conn.getQueryInterface();
await queryInterface.changeColumn("History", "type", DataTypes.TEXT);
await this._db.history.HistoryModel.update({ type: "Map" }, { where: { type: "Pad" } });
await queryInterface.changeColumn("History", "type", this._db.history.HistoryModel.getAttributes().type);
await this._db.meta.setMeta("historyPadMigrationCompleted", "1");
}
}

Wyświetl plik

@ -12,7 +12,7 @@ export type HistoryEntryObjectTypes = {
"Line": Omit<Line, "id">;
"View": Omit<View, "id">;
"Type": Omit<Type, "id">;
"Pad": MapData;
"Map": MapData;
};
export type HistoryEntryType = keyof HistoryEntryObjectTypes;
@ -34,7 +34,7 @@ export type GenericHistoryEntry<ObjectTypes extends Record<HistoryEntryType, any
objectAfter?: undefined;
} : {
objectAfter: ObjectTypes[Type];
}) & (Type extends "Pad" ? {
}) & (Type extends "Map" ? {
objectId?: undefined;
} : {
objectId: ID;