mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
* bump version * Sample data source (#9501) * Added sample data populating script * added expand-collapse in add data soure menu * Sample database * Design changes * Added CTA to buttons and added design changes * Added code sanity fix for some services * changed configration for create sampke db and code sanity fix * Removed logs * Added xlsx in dependency * added migration for sample db * Added loggin for testing * Added await in migration * Replace excel sheet with JSON files * reverted package-lock file * Fixed issues * dependecy deletion * Added schedular * Added changes for bug fixes and typeorm query for creating sample db * Removed color.scss file import * Add logo in sample application * add documentation link for sample db * fixed migration issue for data queries creation * removed sample db intergration * bump version * Remove .env file and code sanity * deleted migration file --------- Co-authored-by: Kritagya <kriks.iitk@.com> Co-authored-by: Kritagya Kumar <kritagyakumar@192.168.1.6> Co-authored-by: kriks7raptor <kritagya@raptorx.ai> Co-authored-by: gsmithun4 <gsmithun4@gmail.com> * Add data-cy for drag drop empty canvas card (#9513) * Add sample db condition on all components (#9516) * Add sample db condition on all components * Changed empty state for container * Condiiton on sample data source --------- Co-authored-by: kriks7raptor <kritagya@raptorx.ai> * Release fix: subpath (#9535) * Add sample db condition on all components * Changed empty state for container * Condiiton on sample data source * fixed subpath issue for workspace setting and folders * Folder change handler in subpath --------- Co-authored-by: kriks7raptor <kritagya@raptorx.ai> * fixed version * fixed version * fixed version * update server version * Bump version to v2.39.0 --------- Co-authored-by: kriks7iitk <34170719+kriks7iitk@users.noreply.github.com> Co-authored-by: Kritagya <kriks.iitk@.com> Co-authored-by: Kritagya Kumar <kritagyakumar@192.168.1.6> Co-authored-by: kriks7raptor <kritagya@raptorx.ai> Co-authored-by: Ajith KV <ajith.jaban@gmail.com> Co-authored-by: kriks7iitk <kriks.iitk@gmail.com> Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> Co-authored-by: Muhsin Shah <muhsinshah21@gmail.com>
143 lines
4.1 KiB
TypeScript
143 lines
4.1 KiB
TypeScript
import * as path from 'path';
|
|
import * as dotenv from 'dotenv';
|
|
import * as fs from 'fs';
|
|
import { ExecFileSyncOptions, execFileSync } from 'child_process';
|
|
import { buildAndValidateDatabaseConfig } from './database-config-utils';
|
|
import { isEmpty } from 'lodash';
|
|
async function createDatabaseFromFile(envPath: string): Promise<void> {
|
|
const result = dotenv.config({ path: envPath });
|
|
|
|
if (process.env.PG_DB_OWNER === 'false') {
|
|
console.log('Skipping database creation');
|
|
return;
|
|
}
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
|
|
await createDatabase();
|
|
}
|
|
|
|
async function createDatabase(): Promise<void> {
|
|
const { value: envVars, error } = buildAndValidateDatabaseConfig();
|
|
|
|
if (error) {
|
|
throw new Error(`Config validation error: ${error.message}`);
|
|
}
|
|
|
|
if (envVars.PG_DB_OWNER === 'false') {
|
|
console.log('Skipping database creation');
|
|
return;
|
|
}
|
|
|
|
const dbNameFromArg = process.argv[2];
|
|
|
|
if (dbNameFromArg) {
|
|
await createDb(envVars, dbNameFromArg);
|
|
} else {
|
|
await createDb(envVars, envVars.PG_DB);
|
|
if (process.env.ENABLE_TOOLJET_DB === 'true') {
|
|
await createTooljetDb(envVars, envVars.TOOLJET_DB);
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkCommandAvailable(command: string) {
|
|
try {
|
|
const options = { env: process.env } as ExecFileSyncOptions;
|
|
execFileSync('which', [command], options);
|
|
} catch (error) {
|
|
throw `Error: ${command} not found. Make sure it's installed and available in the system's PATH.`;
|
|
}
|
|
}
|
|
|
|
function executeCreateDb(host: string, port: string, user: string, password: string, dbName: string) {
|
|
const env = Object.assign({}, process.env, { PGPASSWORD: password });
|
|
const createDbArgs = ['-h', host, '-p', port, '-U', user, dbName];
|
|
const options = { env, stdio: 'pipe' } as ExecFileSyncOptions;
|
|
|
|
execFileSync('createdb', createDbArgs, options);
|
|
}
|
|
|
|
async function createDb(envVars, dbName): Promise<void> {
|
|
if (isEmpty(dbName)) {
|
|
throw new Error('Database name cannot be empty');
|
|
}
|
|
|
|
try {
|
|
executeCreateDb(envVars.PG_HOST, envVars.PG_PORT, envVars.PG_USER, envVars.PG_PASS, dbName);
|
|
console.log(`Created database ${dbName}\n`);
|
|
} catch (error) {
|
|
if (error.message.includes(`database "${dbName}" already exists`)) {
|
|
console.log(`Using Application database\nPG_DB: ${dbName}\nPG_HOST: ${envVars.PG_HOST}\n`);
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
async function createTooljetDb(envVars, dbName): Promise<void> {
|
|
if (isEmpty(dbName)) {
|
|
throw new Error('Database name cannot be empty');
|
|
}
|
|
|
|
try {
|
|
executeCreateDb(
|
|
envVars.TOOLJET_DB_HOST,
|
|
envVars.TOOLJET_DB_PORT,
|
|
envVars.TOOLJET_DB_USER,
|
|
envVars.TOOLJET_DB_PASS,
|
|
dbName
|
|
);
|
|
} catch (error) {
|
|
if (error.message.includes(`database "${dbName}" already exists`)) {
|
|
console.log(`Using Tooljet database\nTOOLJET_DB: ${dbName}\nTOOLJET_DB_HOST: ${envVars.TOOLJET_DB_HOST}\n`);
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
async function createSampleDb(envVars, dbName): Promise<void> {
|
|
if (isEmpty(dbName)) {
|
|
throw new Error('Database name cannot be empty');
|
|
}
|
|
|
|
try {
|
|
executeCreateDb(
|
|
envVars.SAMPLE_PG_DB_HOST,
|
|
envVars.SAMPLE_PG_DB_PORT,
|
|
envVars.SAMPLE_PG_DB_USER,
|
|
envVars.SAMPLE_PG_DB_PASS,
|
|
dbName
|
|
);
|
|
} catch (error) {
|
|
if (error.message.includes(`database "${dbName}" already exists`)) {
|
|
console.log(
|
|
`Already present Sample database\n${dbName}\n HOST: ${envVars.SAMPLE_PG_DB_HOST}\n PORT: ${envVars.SAMPLE_PG_DB_PORT}`
|
|
);
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
checkCommandAvailable('createdb');
|
|
const nodeEnvPath = path.resolve(process.cwd(), process.env.NODE_ENV === 'test' ? '../.env.test' : '../.env');
|
|
const fallbackPath = path.resolve(process.cwd(), '../.env');
|
|
|
|
if (fs.existsSync(nodeEnvPath)) {
|
|
createDatabaseFromFile(nodeEnvPath);
|
|
} else if (fs.existsSync(fallbackPath)) {
|
|
createDatabaseFromFile(fallbackPath);
|
|
} else {
|
|
console.log('Picking up config from the environment');
|
|
createDatabase();
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
process.exit(1);
|
|
}
|