var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { generateApolloClient } from '@deep-foundation/hasura/client.js';
import { sql } from '@deep-foundation/hasura/sql.js';
import Debug from 'debug';
import { DeepClient } from '../imports/client.js';
import { api, SCHEMA } from './1616701513782-links.js';
const debug = Debug('deeplinks:migrations:healthz');
const log = debug.extend('log');
const error = debug.extend('error');
export const HEALTHZ_VIEW_NAME = 'healthz';
const client = generateApolloClient({
    path: `${process.env.MIGRATIONS_HASURA_PATH}/v1/graphql`,
    ssl: !!+(process.env.MIGRATIONS_HASURA_SSL || 0),
    secret: process.env.MIGRATIONS_HASURA_SECRET,
});
const deep = new DeepClient({
    apolloClient: client,
});
export const up = () => __awaiter(void 0, void 0, void 0, function* () {
    log('up');
    log('view');
    yield api.sql(sql `CREATE VIEW ${HEALTHZ_VIEW_NAME} AS SELECT 'ok'::text as "status";`);
    yield api.query({
        type: 'track_table',
        args: {
            schema: SCHEMA,
            name: HEALTHZ_VIEW_NAME,
        },
    });
    yield api.query({
        type: 'create_select_permission',
        args: {
            table: HEALTHZ_VIEW_NAME,
            role: 'undefined',
            permission: {
                columns: '*',
                filter: {},
                limit: 999,
                allow_aggregations: true
            }
        }
    });
});
export const down = () => __awaiter(void 0, void 0, void 0, function* () {
    log('down');
    log('view');
    yield api.query({
        type: 'drop_select_permission',
        args: {
            table: HEALTHZ_VIEW_NAME,
            role: 'undefined',
        }
    });
    yield api.query({
        type: 'untrack_table',
        args: {
            table: {
                schema: SCHEMA,
                name: HEALTHZ_VIEW_NAME,
            },
            cascade: true,
        },
    });
    yield api.sql(sql `
    DROP VIEW IF EXISTS ${HEALTHZ_VIEW_NAME} CASCADE;
  `);
});
//# sourceMappingURL=1689630159473-healthz.js.map