309 lines
10 KiB
TypeScript
309 lines
10 KiB
TypeScript
import { DATASQUIREL_LoggedInUser, UserType } from "../../../types";
|
|
import path from "path";
|
|
|
|
type Param = {
|
|
user?: DATASQUIREL_LoggedInUser | UserType;
|
|
userId?: string | number | null;
|
|
appDir?: string;
|
|
dataDir?: string;
|
|
};
|
|
export default function grabDirNames(param?: Param) {
|
|
const appDir = param?.appDir || process.env.DSQL_APP_DIR;
|
|
const DATA_DIR = param?.dataDir || process.env.DSQL_DATA_DIR || "/data";
|
|
|
|
const finalUserId = param?.user?.id || param?.userId;
|
|
|
|
if (!appDir)
|
|
throw new Error("Please provide the `DSQL_APP_DIR` env variable.");
|
|
|
|
if (!DATA_DIR)
|
|
throw new Error("Please provide the `DATA_DIR` env variable.");
|
|
|
|
const STATIC_ROOT = path.join(DATA_DIR, "static");
|
|
|
|
const staticConfigDir = path.join(DATA_DIR, "static-config");
|
|
const staticNGINXConfigFile = path.join(staticConfigDir, "default.conf");
|
|
|
|
const mainReverseProxyConfigDir = path.join(DATA_DIR, "reverse-proxy");
|
|
const mainReverseProxyConfigFile = path.join(
|
|
mainReverseProxyConfigDir,
|
|
"default.conf"
|
|
);
|
|
const mainReverseProxyTemplatesDir = path.join(
|
|
mainReverseProxyConfigDir,
|
|
"templates"
|
|
);
|
|
const mainReverseProxyTemplatesDefaultFile = path.join(
|
|
mainReverseProxyTemplatesDir,
|
|
"default.conf.template"
|
|
);
|
|
|
|
const publicImagesDir = path.join(STATIC_ROOT, `images`);
|
|
|
|
const publicDir = path.join(appDir, "public");
|
|
const publicSSLDir = path.join(publicDir, "documents", "ssl");
|
|
const appSSLDir = path.join(appDir, "ssl");
|
|
const mainSSLDir = path.join(DATA_DIR, "ssl");
|
|
|
|
const maxscaleSSLDir = path.join(mainSSLDir, "maxscale");
|
|
const mainDBSSLDir = path.join(mainSSLDir, "main");
|
|
const replica1DBSSLDir = path.join(mainSSLDir, "replica-1");
|
|
const replica2DBSSLDir = path.join(mainSSLDir, "replica-2");
|
|
|
|
const privateDataDir = path.join(DATA_DIR, "private");
|
|
|
|
/**
|
|
* # DB Dir names
|
|
* @description Database related Directories
|
|
*/
|
|
const mainDbDataDir = path.join(DATA_DIR, "db");
|
|
const mainDbGrastateDatFile = path.join(mainDbDataDir, "grastate.dat");
|
|
const replica1DbDataDir = path.join(DATA_DIR, "replica-1");
|
|
|
|
const mariadbMainConfigDir = path.join(DATA_DIR, "db-config", "main");
|
|
const mariadbReplicaConfigDir = path.join(DATA_DIR, "db-config", "replica");
|
|
const maxscaleConfigDir = path.join(DATA_DIR, "db-config", "maxscale");
|
|
|
|
const mariadbMainConfigFile = path.join(
|
|
mariadbMainConfigDir,
|
|
"default.cnf"
|
|
);
|
|
const mariadbReplicaConfigFile = path.join(
|
|
mariadbReplicaConfigDir,
|
|
"default.cnf"
|
|
);
|
|
const galeraConfigFile = path.join(mariadbMainConfigDir, "galera.cnf");
|
|
const galeraReplicaConfigFile = path.join(
|
|
mariadbReplicaConfigDir,
|
|
"galera.cnf"
|
|
);
|
|
const maxscaleConfigFile = path.join(maxscaleConfigDir, "maxscale.cnf");
|
|
|
|
/**
|
|
* # Schema Dir names
|
|
* @description
|
|
*/
|
|
const oldSchemasDir = path.join(appDir, "jsonData", "dbSchemas");
|
|
const appSchemaJSONFile = path.join(oldSchemasDir, "1.json");
|
|
const tempDirName = ".tmp";
|
|
|
|
const appConfigDir = path.join(appDir, "jsonData", "config");
|
|
const appConfigJSONFile = path.join(appConfigDir, "app-config.json");
|
|
|
|
if (!privateDataDir)
|
|
throw new Error(
|
|
"Please provide the `DSQL_DB_SCHEMA_DIR` env variable."
|
|
);
|
|
|
|
const pakageSharedDir = path.join(appDir, `package-shared`);
|
|
|
|
const mainDbTypeDefFile = path.join(pakageSharedDir, `types/dsql.ts`);
|
|
const mainShemaJSONFilePath = path.join(oldSchemasDir, `main.json`);
|
|
const defaultTableFieldsJSONFilePath = path.join(
|
|
pakageSharedDir,
|
|
`data/defaultFields.json`
|
|
);
|
|
|
|
const usersSchemaDir = path.join(privateDataDir, `users`);
|
|
const targetUserPrivateDir = finalUserId
|
|
? path.join(usersSchemaDir, `user-${finalUserId}`)
|
|
: undefined;
|
|
const userTempSQLFilePath = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `tmp.sql`)
|
|
: undefined;
|
|
const userMainShemaJSONFilePath = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `main.json`)
|
|
: undefined;
|
|
|
|
const userConfigJSONFilePath = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `config.json`)
|
|
: undefined;
|
|
|
|
const userSchemaMainJSONFilePath = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `main.json`)
|
|
: undefined;
|
|
const userPrivateMediaDir = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `media`)
|
|
: undefined;
|
|
const userPrivateExportsDir = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `export`)
|
|
: undefined;
|
|
const userPrivateSQLExportsDir = userPrivateExportsDir
|
|
? path.join(userPrivateExportsDir, `sql`)
|
|
: undefined;
|
|
const userPrivateTempSQLExportsDir = userPrivateSQLExportsDir
|
|
? path.join(userPrivateSQLExportsDir, tempDirName)
|
|
: undefined;
|
|
const userPrivateTempJSONSchemaFilePath = userPrivateTempSQLExportsDir
|
|
? path.join(userPrivateTempSQLExportsDir, `schema.json`)
|
|
: undefined;
|
|
const userPrivateDbExportZipFileName = `db-export.zip`;
|
|
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
|
? path.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
|
: undefined;
|
|
|
|
const userPublicMediaDir = finalUserId
|
|
? path.join(publicImagesDir, `user-images/user-${finalUserId}`)
|
|
: undefined;
|
|
|
|
const userPrivateDbImportZipFileName = `db-export.zip`;
|
|
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
|
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
|
: undefined;
|
|
|
|
const dbNginxLoadBalancerConfigFile = path.join(
|
|
appDir,
|
|
"docker/services/mariadb/load-balancer/config/template/nginx.conf"
|
|
);
|
|
|
|
let dockerComposeFile = path.join(appDir, "docker-compose.yml");
|
|
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
|
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
|
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
|
|
const dsqlDockerComposeFile = path.join(appDir, dsqlDockerComposeFileName);
|
|
const dsqlDockerComposeFileAlt = path.join(
|
|
appDir,
|
|
dsqlDockerComposeFileNameAlt
|
|
);
|
|
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
|
const dbDockerComposeFileAlt = path.join(appDir, "db.docker-compose.yaml");
|
|
const extraDockerComposeFile = path.join(
|
|
appDir,
|
|
"extra.docker-compose.yml"
|
|
);
|
|
const extraDockerComposeFileAlt = path.join(
|
|
appDir,
|
|
"extra.docker-compose.yaml"
|
|
);
|
|
|
|
const siteSetupFile = path.join(appDir, "site-setup.json");
|
|
|
|
const envFile = path.join(appDir, ".env");
|
|
const dsqlEnvFileName = "dsql.env";
|
|
const dsqlEnvFile = path.join(appDir, dsqlEnvFileName);
|
|
|
|
/**
|
|
* # Backup Dir names
|
|
* @description
|
|
*/
|
|
const mainBackupDir = path.join(DATA_DIR, "backups");
|
|
const userBackupDir = targetUserPrivateDir
|
|
? path.join(targetUserPrivateDir, `backups`)
|
|
: undefined;
|
|
|
|
const sqlBackupDirName = `sql`;
|
|
const schemasBackupDirName = `schema`;
|
|
|
|
/**
|
|
* # Distribution Names
|
|
*/
|
|
const distroDirName = "distro" as const;
|
|
const distroAppDirName = "dsql-app" as const;
|
|
const distroDataDirName = "dsql-data" as const;
|
|
const distroCommunityName = "dsql-community" as const;
|
|
const distroCommunityExportTarName =
|
|
`${distroCommunityName}.tar.xz` as const;
|
|
const distroProName = "dsql-pro" as const;
|
|
const distroProExportTarName = `${distroProName}.tar.xz` as const;
|
|
const distroEnterpriseName = "dsql-enterprise" as const;
|
|
const distroEnterpriseExportTarName =
|
|
`${distroEnterpriseName}.tar.xz` as const;
|
|
|
|
const communityDistroTempDir = path.resolve(
|
|
appDir,
|
|
"build",
|
|
"community",
|
|
".tmp"
|
|
);
|
|
const communityDistroDir = path.resolve(
|
|
communityDistroTempDir,
|
|
distroDirName
|
|
);
|
|
|
|
return {
|
|
appDir,
|
|
privateDataDir,
|
|
oldSchemasDir,
|
|
userConfigJSONFilePath,
|
|
mainShemaJSONFilePath,
|
|
mainDbTypeDefFile,
|
|
tempDirName,
|
|
defaultTableFieldsJSONFilePath,
|
|
usersSchemaDir,
|
|
targetUserPrivateDir,
|
|
userSchemaMainJSONFilePath,
|
|
userPrivateMediaDir,
|
|
userPrivateExportsDir,
|
|
userPrivateSQLExportsDir,
|
|
userPrivateTempSQLExportsDir,
|
|
userPrivateTempJSONSchemaFilePath,
|
|
userPrivateDbExportZipFileName,
|
|
userPrivateDbExportZipFilePath,
|
|
userPrivateDbImportZipFileName,
|
|
userPrivateDbImportZipFilePath,
|
|
dbNginxLoadBalancerConfigFile,
|
|
dockerComposeFile,
|
|
dockerComposeFileAlt,
|
|
dsqlDockerComposeFile,
|
|
dsqlDockerComposeFileAlt,
|
|
extraDockerComposeFile,
|
|
extraDockerComposeFileAlt,
|
|
siteSetupFile,
|
|
envFile,
|
|
dsqlEnvFileName,
|
|
dsqlEnvFile,
|
|
userPublicMediaDir,
|
|
userTempSQLFilePath,
|
|
STATIC_ROOT,
|
|
appConfigJSONFile,
|
|
appConfigDir,
|
|
mariadbMainConfigDir,
|
|
mariadbMainConfigFile,
|
|
maxscaleConfigDir,
|
|
mariadbReplicaConfigDir,
|
|
DATA_DIR,
|
|
publicDir,
|
|
publicSSLDir,
|
|
appSSLDir,
|
|
maxscaleConfigFile,
|
|
mariadbReplicaConfigFile,
|
|
mainSSLDir,
|
|
mainDbDataDir,
|
|
replica1DbDataDir,
|
|
galeraConfigFile,
|
|
galeraReplicaConfigFile,
|
|
dbDockerComposeFile,
|
|
dbDockerComposeFileAlt,
|
|
mainDbGrastateDatFile,
|
|
appSchemaJSONFile,
|
|
mainBackupDir,
|
|
userBackupDir,
|
|
sqlBackupDirName,
|
|
schemasBackupDirName,
|
|
userMainShemaJSONFilePath,
|
|
maxscaleSSLDir,
|
|
mainDBSSLDir,
|
|
replica1DBSSLDir,
|
|
replica2DBSSLDir,
|
|
staticConfigDir,
|
|
staticNGINXConfigFile,
|
|
mainReverseProxyConfigDir,
|
|
mainReverseProxyConfigFile,
|
|
mainReverseProxyTemplatesDir,
|
|
mainReverseProxyTemplatesDefaultFile,
|
|
dsqlDockerComposeFileName,
|
|
dsqlDockerComposeFileNameAlt,
|
|
distroDirName,
|
|
distroAppDirName,
|
|
distroDataDirName,
|
|
distroCommunityName,
|
|
distroCommunityExportTarName,
|
|
distroProName,
|
|
distroProExportTarName,
|
|
distroEnterpriseName,
|
|
distroEnterpriseExportTarName,
|
|
communityDistroTempDir,
|
|
communityDistroDir,
|
|
};
|
|
}
|