All files / blong-int-adapter/mysql/adapter/sql sqlUnitCreate.ts

100% Statements 28/28
75% Branches 3/4
100% Functions 1/1
100% Lines 28/28

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 291x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {handler} from '@feasibleone/blong';
 
/**
 * sqlUnitCreate — creates the `unit` test table in the blong-integration
 * database if it does not already exist.
 * This handler is called from integration tests to set up the test schema.
 */
export default handler(
    () =>
        async function sqlUnitCreate(
            _params: Record<string, never>,
            _$meta: Record<string, unknown>,
        ): Promise<{table: string; existed: boolean}> {
            const existed = await this.config?.context?.queryBuilder?.schema.hasTable('sql_unit');
            if (!existed) {
                await this.config?.context?.queryBuilder?.schema.createTable(
                    'sql_unit',
                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                    (table: any) => {
                        table.increments('unitId');
                        table.string('unitName', 255).notNullable();
                        table.text('unitDescription').nullable();
                    },
                );
            }
            return {table: 'sql_unit', existed: existed ?? false};
        },
);