feat(activeDid): implement migration to separate active_identity table
- Add migration 003 with data migration logic to prevent data loss - Create dedicated ActiveIdentity interface in separate file for better architecture - Implement $getActiveIdentity method in PlatformServiceMixin - Enhance $updateActiveDid with dual-write pattern for backward compatibility - Maintain separation of concerns between settings and active identity types - Follow project architectural pattern with dedicated type definition files The migration creates active_identity table alongside existing settings, automatically copying existing activeDid data to prevent user data loss. Dual-write pattern ensures backward compatibility during transition. Migration includes: - Schema creation with proper constraints and indexes - Automatic data transfer from settings.activeDid to active_identity.activeDid - Validation to ensure data exists before migration - Atomic operation: schema and data migration happen together
This commit is contained in:
@@ -58,6 +58,7 @@ import {
|
||||
generateInsertStatement,
|
||||
generateUpdateStatement,
|
||||
} from "@/utils/sqlHelpers";
|
||||
import { ActiveIdentity } from "@/db/tables/activeIdentity";
|
||||
|
||||
// =================================================
|
||||
// TYPESCRIPT INTERFACES
|
||||
@@ -548,6 +549,40 @@ export const PlatformServiceMixin = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get active identity from the new active_identity table
|
||||
* This replaces the activeDid field in settings for better architecture
|
||||
*/
|
||||
async $getActiveIdentity(): Promise<ActiveIdentity> {
|
||||
try {
|
||||
const result = await this.$dbQuery(
|
||||
"SELECT id, activeDid, lastUpdated FROM active_identity WHERE id = 1",
|
||||
);
|
||||
|
||||
if (result?.values?.length) {
|
||||
const [id, activeDid, lastUpdated] = result.values[0];
|
||||
return {
|
||||
id: id as number,
|
||||
activeDid: activeDid as string,
|
||||
lastUpdated: lastUpdated as string,
|
||||
};
|
||||
}
|
||||
|
||||
// Return default if no record exists
|
||||
return {
|
||||
id: 1,
|
||||
activeDid: "",
|
||||
lastUpdated: new Date().toISOString(),
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
"[PlatformServiceMixin] Error getting active identity:",
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Transaction wrapper with automatic rollback on error
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user