'use strict';
import { isDev, isProdOrDemo } from '../../../fd-toolbox/lib/environments.js';
import { logInfo } from '../../../fd-toolbox/server/logging/logger.js';
import { seed } from '../seeding/seed-master-data.js';
import { migrate, createDb, generateMigrations, dropDb as dropDb$1, initializeDb, emptyAllTables } from '../../db/db-connection.js';
import { flushRemoteCache } from '../../../fd-toolbox/server/cachings/fd-remote-cache.js';
import * as schema from '../../../../generated/schema.js';
import { resourceHandlerDynamicImportMap } from '../../../../generated/meta/crud-handler-map.js';
import { initializeInternalResourceMetaIfNeeded } from '../../meta/server/resources/init-internal-resource-metas-from-json.js';
import { setHandlerMap } from '../../meta/server/modules/handler-map.js';
import { appPackageNames } from '../../../base-repo/app-constants/app-packages-names.js';
import { migrationStatusMessages } from '../../db/utils/run-migration-command.js';

var __defProp=Object['defineProperty'],__name=(_0x5884da,_0x323521)=>__defProp(_0x5884da,'name',{'value':_0x323521,'configurable':!![]});async function runMigrations(){try{await migrate();}catch{isDev()?(await dropDevDb(),await createDb(),await migrate()):process['exit'](-0x2*-0xd79+-0x19ec+-0x105);}}__name(runMigrations,'runMigrations');async function runGenerateMigrations(){await createDb(),logInfo(migrationStatusMessages['generatingMigrations']),await generateMigrations(appPackageNames['saasKit']);}__name(runGenerateMigrations,'runGenerateMigrations');async function dropDb(){await dropDb$1();}__name(dropDb,'dropDb');async function dropDevDb(){!isProdOrDemo()&&await dropDb();}__name(dropDevDb,'dropDevDb');async function recreateDeployDb(){await flushRemoteCache(),await dropDb(),await runMigrations(),setHandlerMap(resourceHandlerDynamicImportMap),initializeDb(schema),initializeInternalResourceMetaIfNeeded(),await seed();}__name(recreateDeployDb,'recreateDeployDb');async function resetDemoDataInExistingDb(){await flushRemoteCache(),await emptyAllTables(),await seed();}__name(resetDemoDataInExistingDb,'resetDemoDataInExistingDb');

export { dropDb, dropDevDb, recreateDeployDb, resetDemoDataInExistingDb, runGenerateMigrations, runMigrations };
