MCPcopy Create free account
hub / github.com/bytebase/bytebase / migrateSqlEditorTabKeys

Function migrateSqlEditorTabKeys

frontend/src/utils/storage-migrate.ts:117–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115}
116
117function migrateSqlEditorTabKeys() {
118 // Old: "bb.sql-editor-tab.{project}.{email}.opening-tab-list"
119 // → "bb.sql-editor.tabs.{project}.{email}"
120 // Old: "bb.sql-editor-tab.{project}.{email}.current-tab-id"
121 // → "bb.sql-editor.current-tab.{project}.{email}"
122 //
123 // Must run here (before stores init) because useDynamicLocalStorage
124 // writes default [] to the new key when it doesn't exist yet,
125 // which would race with the in-store migrateTabKeys.
126 const OLD_PREFIX = "bb.sql-editor-tab.";
127 const TAB_LIST_SUFFIX = ".opening-tab-list";
128 const CURRENT_TAB_SUFFIX = ".current-tab-id";
129
130 const keysToMigrate: [string, string][] = [];
131 for (let i = 0; i < localStorage.length; i++) {
132 const key = localStorage.key(i);
133 if (!key?.startsWith(OLD_PREFIX)) continue;
134
135 if (key.endsWith(TAB_LIST_SUFFIX)) {
136 // "bb.sql-editor-tab.{project}.{email}.opening-tab-list"
137 // → middle = "{project}.{email}"
138 const middle = key.slice(OLD_PREFIX.length, -TAB_LIST_SUFFIX.length);
139 keysToMigrate.push([key, `bb.sql-editor.tabs.${middle}`]);
140 } else if (key.endsWith(CURRENT_TAB_SUFFIX)) {
141 const middle = key.slice(OLD_PREFIX.length, -CURRENT_TAB_SUFFIX.length);
142 keysToMigrate.push([key, `bb.sql-editor.current-tab.${middle}`]);
143 }
144 }
145 for (const [oldKey, newKey] of keysToMigrate) {
146 moveKey(oldKey, newKey);
147 }
148}
149
150function migrateSqlEditorConnKeys() {
151 // "bb.sql-editor.connection-pane.expanded_{env}.{email}"

Callers 1

migrateStorageKeysFunction · 0.85

Calls 2

moveKeyFunction · 0.85
keyMethod · 0.45

Tested by

no test coverage detected