feat: implement ActiveDid migration to active_identity table

- Add $getActiveIdentity() method to PlatformServiceMixin interface
- Update HomeView.vue to use new active_identity API methods
- Update ContactsView.vue to use new active_identity API methods
- Fix apiServer default handling in PlatformServiceMixin
- Ensure DEFAULT_ENDORSER_API_SERVER is used when apiServer is empty
- Add comprehensive logging for debugging ActiveDid migration
- Resolve TypeScript interface issues with Vue mixins
This commit is contained in:
Matthew Raymer
2025-09-02 10:20:54 +00:00
parent a522a10fb7
commit b374f2e5a1
4 changed files with 449 additions and 68 deletions

View File

@@ -4,6 +4,7 @@ import {
} from "../services/migrationService";
import { DEFAULT_ENDORSER_API_SERVER } from "@/constants/app";
import { arrayBufferToBase64 } from "@/libs/crypto";
import { logger } from "@/utils/logger";
// Generate a random secret for the secret table
@@ -151,6 +152,50 @@ const MIGRATIONS = [
AND EXISTS (SELECT 1 FROM settings WHERE id = 1 AND activeDid IS NOT NULL AND activeDid != '');
`,
},
{
name: "004_remove_activeDid_from_settings",
sql: `
-- Remove activeDid column from settings table (moved to active_identity)
-- Note: SQLite doesn't support DROP COLUMN in older versions
-- This migration will be skipped if DROP COLUMN is not supported
-- The activeDid column will remain but won't be used by the application
-- Try to drop the activeDid column (works in SQLite 3.35.0+)
ALTER TABLE settings DROP COLUMN activeDid;
`,
},
{
name: "005_eliminate_master_settings_key",
sql: `
-- Eliminate MASTER_SETTINGS_KEY concept - remove confusing id=1 row
-- This creates clean separation: active_identity for current identity, settings for identity config
-- Delete the confusing MASTER_SETTINGS_KEY row (id=1 with accountDid=NULL)
DELETE FROM settings WHERE id = 1 AND accountDid IS NULL;
-- Reset auto-increment to start from 1 again
DELETE FROM sqlite_sequence WHERE name = 'settings';
`,
},
{
name: "006_add_unique_constraint_accountDid",
sql: `
-- Add unique constraint to prevent duplicate accountDid values
-- This ensures data integrity: each identity can only have one settings record
-- First, remove any duplicate accountDid entries (keep the most recent one)
DELETE FROM settings
WHERE id NOT IN (
SELECT MAX(id)
FROM settings
WHERE accountDid IS NOT NULL
GROUP BY accountDid
) AND accountDid IS NOT NULL;
-- Add unique constraint on accountDid
CREATE UNIQUE INDEX IF NOT EXISTS idx_settings_accountDid_unique ON settings(accountDid);
`,
},
];
/**
@@ -162,8 +207,14 @@ export async function runMigrations<T>(
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>,
extractMigrationNames: (result: T) => Set<string>,
): Promise<void> {
logger.info("[Migration] Starting database migrations");
for (const migration of MIGRATIONS) {
logger.debug("[Migration] Registering migration:", migration.name);
registerMigration(migration);
}
logger.info("[Migration] Running migration service");
await runMigrationsService(sqlExec, sqlQuery, extractMigrationNames);
logger.info("[Migration] Database migrations completed");
}