All files / services migrations.service.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                              2x 33x 28x           2x 5x 5x 3x     2x 1x   1x             2x 6x 5x    
/**
 * Migrations service for querying Alembic migration status
 */
 
import axios from 'axios';
import { apiClient } from '@/lib/api';
import type {
    MigrationListResponse,
    CurrentRevisionResponse,
    MigrationHistoryResponse,
} from '@/types/migrations';
 
/**
 * List all Alembic revisions
 */
export const listMigrations = async (): Promise<MigrationListResponse> => {
    const response = await apiClient.get<MigrationListResponse>('/migrations');
    return response.data;
};
 
/**
 * Get current database revision
 */
export const getCurrentMigration = async (): Promise<CurrentRevisionResponse | null> => {
    try {
        const response = await apiClient.get<CurrentRevisionResponse>('/migrations/current');
        return response.data;
    } catch (error: unknown) {
        // Return null if no current revision (404)
        if (axios.isAxiosError(error) && error.response?.status === 404) {
            return null;
        }
        throw error;
    }
};
 
/**
 * Get full migration history
 */
export const getMigrationHistory = async (): Promise<MigrationHistoryResponse> => {
    const response = await apiClient.get<MigrationHistoryResponse>('/migrations/history');
    return response.data;
};