kopia lustrzana https://github.com/FacilMap/facilmap
Rename "Pad" to "Map" in HistoryEntry.type
rodzic
7a5d74dc74
commit
b2bbe1c2a2
|
@ -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: {
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,6 +18,7 @@ export interface MetaProperties {
|
|||
typesIdxMigrationCompleted: "1";
|
||||
viewsIdxMigrationCompleted: "1";
|
||||
fieldIconsMigrationCompleted: "1";
|
||||
historyPadMigrationCompleted: "1";
|
||||
}
|
||||
|
||||
export default class DatabaseMeta {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Ładowanie…
Reference in New Issue