@dbcube/cli 1.1.9 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +58 -0
- package/dbcube.config.js +15 -0
- package/package.json +2 -2
- package/src/commands/run/database/create/createDatabase.js +7 -20
- package/src/commands/run/database/create/index.js +22 -32
- package/src/commands/run/seeder/add.js +46 -68
- package/src/commands/run/table/fresh.js +20 -93
- package/src/commands/run/table/refresh.js +21 -89
- package/src/commands/run/trigger/fresh.js +46 -68
- package/src/index.js +1 -1
- package/src/lib/ProgressIndicator.js +35 -27
- package/.lh/.lhignore +0 -6
- package/.lh/package.json.json +0 -26
package/.npmignore
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Directories
|
|
2
|
+
examples
|
|
3
|
+
|
|
4
|
+
# Ignorar dependencias y configuraciones de desarrollo
|
|
5
|
+
node_modules/
|
|
6
|
+
npm-debug.log*
|
|
7
|
+
yarn-debug.log*
|
|
8
|
+
yarn-error.log*
|
|
9
|
+
|
|
10
|
+
# Ignorar carpetas y archivos irrelevantes
|
|
11
|
+
.vscode/
|
|
12
|
+
.lh
|
|
13
|
+
.idea/
|
|
14
|
+
.DS_Store
|
|
15
|
+
Thumbs.db
|
|
16
|
+
*.log
|
|
17
|
+
|
|
18
|
+
# Ignorar configuraciones del proyecto
|
|
19
|
+
.env
|
|
20
|
+
.env.*.local
|
|
21
|
+
package-lock.json
|
|
22
|
+
|
|
23
|
+
# Ignorar archivos del sistema
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
*.tmp
|
|
27
|
+
*.temp
|
|
28
|
+
|
|
29
|
+
# Ignorar carpetas de trabajo
|
|
30
|
+
temp/
|
|
31
|
+
logs/
|
|
32
|
+
debug/
|
|
33
|
+
|
|
34
|
+
# Ignorar archivos de compilación
|
|
35
|
+
src/
|
|
36
|
+
tsconfig.json
|
|
37
|
+
tsconfig.tsbuildinfo
|
|
38
|
+
|
|
39
|
+
# Ignorar pruebas y configuraciones
|
|
40
|
+
tests/
|
|
41
|
+
__tests__/
|
|
42
|
+
__mocks__/
|
|
43
|
+
coverage/
|
|
44
|
+
jest.config.js
|
|
45
|
+
|
|
46
|
+
# Ignorar documentación o ejemplos no necesarios
|
|
47
|
+
docs/
|
|
48
|
+
examples/
|
|
49
|
+
|
|
50
|
+
# Asegurarse de incluir solo lo esencial
|
|
51
|
+
!.npmignore
|
|
52
|
+
tsconfig.json
|
|
53
|
+
tsup.config.ts
|
|
54
|
+
|
|
55
|
+
.dbcube
|
|
56
|
+
dbcube
|
|
57
|
+
.env
|
|
58
|
+
*.db
|
package/dbcube.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbcube/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dbcube": "node src/index.js"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"description": "",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dbcube/schema-builder": "^1.0.
|
|
16
|
+
"@dbcube/schema-builder": "^1.0.20",
|
|
17
17
|
"@inquirer/prompts": "^7.8.4",
|
|
18
18
|
"alwait": "^1.0.0",
|
|
19
19
|
"chalk": "^5.6.0",
|
|
@@ -16,21 +16,9 @@ async function createDatabasePhysically(databaseName) {
|
|
|
16
16
|
console.log('Uso: node createDatabase.js --name=<nombre> | -n <nombre>');
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
console.log('\n')
|
|
21
|
-
const spinner = ora(`Creando base de datos '${databaseName}'...`).start();
|
|
22
|
-
|
|
23
|
-
console.log("\n")
|
|
24
|
-
console.log(`Inicializando Schema para: ${databaseName}`)
|
|
25
19
|
const schema = new Schema(databaseName);
|
|
26
|
-
console.log(`Creando base de datos: ${databaseName}`)
|
|
27
20
|
await schema.createDatabase();
|
|
28
|
-
|
|
29
|
-
await alwait(1000);
|
|
30
|
-
spinner.succeed(`Base de datos '${databaseName}' creada correctamente!\n`);
|
|
31
|
-
|
|
32
|
-
console.log(`✅ Base de datos '${databaseName}' creada exitosamente`);
|
|
33
|
-
|
|
21
|
+
|
|
34
22
|
} catch (error) {
|
|
35
23
|
console.log('\n')
|
|
36
24
|
console.error('❌ Error al crear la base de datos:', error.message || error);
|
|
@@ -41,10 +29,10 @@ async function createDatabasePhysically(databaseName) {
|
|
|
41
29
|
// Procesar argumentos de línea de comandos
|
|
42
30
|
function parseArguments(args) {
|
|
43
31
|
const parsedArgs = {};
|
|
44
|
-
|
|
32
|
+
|
|
45
33
|
for (let i = 0; i < args.length; i++) {
|
|
46
34
|
const arg = args[i];
|
|
47
|
-
|
|
35
|
+
|
|
48
36
|
if (arg.startsWith('--name=')) {
|
|
49
37
|
parsedArgs.name = arg.split('=')[1];
|
|
50
38
|
} else if (arg === '--name' || arg === '-n') {
|
|
@@ -57,23 +45,22 @@ function parseArguments(args) {
|
|
|
57
45
|
i++; // Saltar el siguiente argumento
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
|
-
|
|
48
|
+
|
|
61
49
|
return parsedArgs;
|
|
62
50
|
}
|
|
63
51
|
|
|
64
52
|
// Función principal
|
|
65
53
|
async function main() {
|
|
66
|
-
console.
|
|
67
|
-
|
|
54
|
+
console.clear();
|
|
68
55
|
try {
|
|
69
56
|
const parsedArgs = parseArguments(args);
|
|
70
|
-
|
|
57
|
+
|
|
71
58
|
if (!parsedArgs.name) {
|
|
72
59
|
console.error('❌ Error: Debe proporcionar el nombre de la base de datos');
|
|
73
60
|
console.log('Uso: --name=<nombre> | -n <nombre> | --database=<nombre> | -d <nombre>');
|
|
74
61
|
process.exit(1);
|
|
75
62
|
}
|
|
76
|
-
|
|
63
|
+
|
|
77
64
|
await createDatabasePhysically(parsedArgs.name);
|
|
78
65
|
} catch (error) {
|
|
79
66
|
console.error('Error inesperado:', error);
|
|
@@ -10,17 +10,18 @@ const path = require('path');
|
|
|
10
10
|
* Función para crear una nueva base de datos con configuración (Proceso completo en dos fases)
|
|
11
11
|
*/
|
|
12
12
|
async function createNewDatabase() {
|
|
13
|
+
console.clear();
|
|
13
14
|
try {
|
|
14
15
|
console.log(`\n💚 ${chalk.green("Proceso de creación de base de datos...")}`);
|
|
15
16
|
console.log('📋 Fase 1: Configuración');
|
|
16
17
|
console.log('🏗️ Fase 2: Creación física\n');
|
|
17
|
-
|
|
18
|
+
|
|
18
19
|
// Fase 1: Ejecutar addDatabaseConfig.js
|
|
19
20
|
console.log('🔧 Iniciando configuración de base de datos...');
|
|
20
21
|
const configCommand = `node "${path.join(__dirname, 'addDatabaseConfig.js')}"`;
|
|
21
|
-
|
|
22
|
+
|
|
22
23
|
try {
|
|
23
|
-
execSync(configCommand, {
|
|
24
|
+
execSync(configCommand, {
|
|
24
25
|
stdio: 'inherit',
|
|
25
26
|
cwd: process.cwd()
|
|
26
27
|
});
|
|
@@ -28,12 +29,12 @@ async function createNewDatabase() {
|
|
|
28
29
|
console.error('❌ Error en la fase de configuración:', error.message);
|
|
29
30
|
process.exit(1);
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
|
|
32
33
|
// Leer el nombre de la base de datos del archivo temporal
|
|
33
34
|
const fs = require('fs');
|
|
34
35
|
const tempFile = path.join(__dirname, '.temp_db_name');
|
|
35
36
|
let databaseName;
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
try {
|
|
38
39
|
databaseName = fs.readFileSync(tempFile, 'utf8');
|
|
39
40
|
// Limpiar el archivo temporal
|
|
@@ -42,14 +43,14 @@ async function createNewDatabase() {
|
|
|
42
43
|
console.error('❌ Error: No se pudo obtener el nombre de la base de datos configurada');
|
|
43
44
|
process.exit(1);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
console.log('\n🏗️ Iniciando creación física de la base de datos...');
|
|
47
|
-
|
|
48
|
+
|
|
48
49
|
// Fase 2: Ejecutar createDatabase.js
|
|
49
50
|
const createCommand = `node "${path.join(__dirname, 'createDatabase.js')}" --name="${databaseName}"`;
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
try {
|
|
52
|
-
execSync(createCommand, {
|
|
53
|
+
execSync(createCommand, {
|
|
53
54
|
stdio: 'inherit',
|
|
54
55
|
cwd: process.cwd()
|
|
55
56
|
});
|
|
@@ -57,7 +58,7 @@ async function createNewDatabase() {
|
|
|
57
58
|
console.error('❌ Error en la fase de creación:', error.message);
|
|
58
59
|
process.exit(1);
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
|
|
61
62
|
console.log(`\n🎉 ${chalk.green("¡Base de datos creada exitosamente!")}`);
|
|
62
63
|
console.log(`✅ Configuración y creación de '${databaseName}' completadas\n`);
|
|
63
64
|
|
|
@@ -72,16 +73,12 @@ async function createNewDatabase() {
|
|
|
72
73
|
* @param {string} databaseName - Nombre de la base de datos a usar
|
|
73
74
|
*/
|
|
74
75
|
async function useExistingDatabase(databaseName) {
|
|
75
|
-
console.log(`\n=== Usando base de datos: ${databaseName} ===\n`);
|
|
76
|
-
|
|
77
|
-
console.log('📋 Usando configuración existente para crear la base de datos...\n');
|
|
78
|
-
|
|
79
76
|
try {
|
|
80
77
|
// Ejecutar createDatabase.js con el nombre de la base de datos existente
|
|
81
78
|
const createCommand = `node "${path.join(__dirname, 'createDatabase.js')}" --name="${databaseName}"`;
|
|
82
|
-
|
|
79
|
+
|
|
83
80
|
try {
|
|
84
|
-
execSync(createCommand, {
|
|
81
|
+
execSync(createCommand, {
|
|
85
82
|
stdio: 'inherit',
|
|
86
83
|
cwd: process.cwd()
|
|
87
84
|
});
|
|
@@ -89,10 +86,7 @@ async function useExistingDatabase(databaseName) {
|
|
|
89
86
|
console.error('❌ Error al crear la base de datos:', error.message);
|
|
90
87
|
process.exit(1);
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
console.log(`\n🎉 ${chalk.green("¡Base de datos lista para usar!")}`);
|
|
94
|
-
console.log(`✅ Base de datos '${databaseName}' creada usando configuración existente\n`);
|
|
95
|
-
|
|
89
|
+
|
|
96
90
|
} catch (error) {
|
|
97
91
|
console.log('❌ Error al crear la base de datos:', error);
|
|
98
92
|
process.exit(1);
|
|
@@ -101,18 +95,16 @@ async function useExistingDatabase(databaseName) {
|
|
|
101
95
|
|
|
102
96
|
async function main() {
|
|
103
97
|
//const dbcubelog = new DBCubeLogger(`❤️ ${chalk.green("Creemos una base de datos...")}\n`);
|
|
104
|
-
console.
|
|
105
|
-
|
|
98
|
+
console.clear();
|
|
99
|
+
console.log(`💚 ${chalk.green("Creemos una base de datos...")}`);
|
|
100
|
+
|
|
106
101
|
try {
|
|
107
102
|
// Obtener las bases de datos configuradas
|
|
108
|
-
const spinner = ora('Cargando bases de datos configuradas...').start();
|
|
109
103
|
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
110
|
-
|
|
111
|
-
spinner.succeed(`¡Configuracion de bases de datos cargada!\n`);
|
|
112
|
-
|
|
104
|
+
|
|
113
105
|
// Preparar las opciones para el menú
|
|
114
106
|
const choices = [];
|
|
115
|
-
|
|
107
|
+
|
|
116
108
|
// Agregar las bases de datos configuradas
|
|
117
109
|
configuredDatabases.forEach(element => {
|
|
118
110
|
choices.push({
|
|
@@ -122,7 +114,7 @@ async function main() {
|
|
|
122
114
|
});
|
|
123
115
|
});
|
|
124
116
|
let selected = 'create';
|
|
125
|
-
if(choices.length > 0){
|
|
117
|
+
if (choices.length > 0) {
|
|
126
118
|
// Agregar opción para crear nueva base de datos
|
|
127
119
|
choices.push({
|
|
128
120
|
name: 'Crear nueva configuración\n',
|
|
@@ -135,9 +127,7 @@ async function main() {
|
|
|
135
127
|
choices: choices
|
|
136
128
|
});
|
|
137
129
|
}
|
|
138
|
-
|
|
139
|
-
console.clear();
|
|
140
|
-
console.log(`\n💚 ${chalk.green("Creemos una base de datos...")}`);
|
|
130
|
+
|
|
141
131
|
if (selected === 'create') {
|
|
142
132
|
// El usuario quiere crear una nueva base de datos
|
|
143
133
|
await createNewDatabase();
|
|
@@ -149,7 +139,7 @@ async function main() {
|
|
|
149
139
|
console.error('Error inesperado:', error);
|
|
150
140
|
}
|
|
151
141
|
}
|
|
152
|
-
|
|
142
|
+
|
|
153
143
|
// Ejecutar el ejemplo
|
|
154
144
|
main().catch(error => {
|
|
155
145
|
console.error('Error fatal:', error);
|
|
@@ -4,93 +4,71 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
6
|
const { default: chalk } = require('chalk');
|
|
7
|
-
const
|
|
7
|
+
const { default: ora } = require('ora');
|
|
8
|
+
const { default: alwait } = require('alwait');
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
// Suprimir logs de dotenv
|
|
11
12
|
process.env.DOTENV_SILENT = 'true';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
console.clear();
|
|
15
|
+
console.log(`\n🌱 ${chalk.green("Ejecutando seeders...")}`);
|
|
16
16
|
try {
|
|
17
17
|
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!fs.existsSync(cubesDir)) {
|
|
22
|
-
throw new Error('❌ The cubes folder does not exist');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
26
|
-
|
|
27
|
-
if (cubeFiles.length === 0) {
|
|
28
|
-
throw new Error('❌ There are no cubes to execute');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return cubeFiles;
|
|
32
|
-
});
|
|
18
|
+
const spinner = ora('Preparando ejecución de seeders...').start();
|
|
19
|
+
await alwait(500);
|
|
20
|
+
const cubesDir = path.join(process.cwd(), 'dbcube', 'cubes');
|
|
33
21
|
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Obtener archivos .cube reales
|
|
40
|
-
const cubeFiles = await progress.showProgress('Analizando archivos .cube', async () => {
|
|
41
|
-
return FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
42
|
-
});
|
|
22
|
+
// Verificar si la carpeta existe
|
|
23
|
+
if (!fs.existsSync(cubesDir)) {
|
|
24
|
+
spinner.fail('Carpeta de cubes no encontrada');
|
|
25
|
+
throw new Error('❌ The cubes folder does not exist');
|
|
26
|
+
}
|
|
43
27
|
|
|
44
|
-
|
|
28
|
+
// Leer todos los archivos en la carpeta
|
|
29
|
+
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube')
|
|
45
30
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
if (cubeFiles.length === 0) {
|
|
32
|
+
spinner.fail('No hay cubes para ejecutar');
|
|
33
|
+
throw new Error('❌ There are no cubes to execute');
|
|
34
|
+
} else {
|
|
35
|
+
spinner.succeed('Cubes encontrados correctamente');
|
|
49
36
|
|
|
50
|
-
|
|
51
|
-
|
|
37
|
+
const loadingSpinner = ora('Cargando configuraciones de base de datos...').start();
|
|
38
|
+
let countTableCreated = 0;
|
|
39
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
40
|
+
loadingSpinner.succeed(`Configuraciones cargadas (${configuredDatabases.length} bases de datos)`);
|
|
52
41
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
43
|
+
for (const config of configuredDatabases) {
|
|
44
|
+
const seederSpinner = ora(`Ejecutando seeders para: ${config.name} (${config.type})...`).start();
|
|
45
|
+
const schema = new Schema(config.name);
|
|
46
|
+
await schema.executeSeeders();
|
|
47
|
+
seederSpinner.succeed(`Seeders ejecutados para: ${config.name}`);
|
|
48
|
+
countTableCreated++;
|
|
56
49
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const schema = new Schema(config.name);
|
|
64
|
-
await schema.executeSeeders();
|
|
65
|
-
|
|
66
|
-
console.log(` ${chalk.green('├─')} ✅ Seeders completados exitosamente`);
|
|
67
|
-
totalSeedersProcessed += realSeeders.length;
|
|
68
|
-
} catch (schemaError) {
|
|
69
|
-
console.log(` ${chalk.red('├─')} ❌ Error durante seeders: ${schemaError.message}`);
|
|
70
|
-
totalSeedersProcessed = 0;
|
|
50
|
+
|
|
51
|
+
if(countTableCreated==0) {
|
|
52
|
+
console.log(`\n⚠️ ${chalk.yellow('No hay seeders para ejecutar.')}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`\n🎉 ${chalk.green(`Seeders ejecutados exitosamente en ${countTableCreated} base(s) de datos!`)}`);
|
|
71
55
|
}
|
|
72
56
|
|
|
73
|
-
console.log(` ${chalk.blue('└─')} ${chalk.green('✓')} Procesamiento de ${config.name} completado`);
|
|
74
57
|
}
|
|
75
|
-
|
|
76
|
-
// Mostrar resumen
|
|
77
|
-
progress.showSummary('seeder', totalSeedersProcessed, configuredDatabases.length);
|
|
78
|
-
|
|
79
58
|
} catch (error) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
console.error(` ${chalk.gray('└─')} Verificar archivo: ${chalk.cyan('dbcube.config.js')}`);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
} else if(error.message.includes("reading 'getDatabase'")){
|
|
88
|
-
console.error('💡 Se sugiere cambiar la configuración o crear la base de datos referenciada.');
|
|
89
|
-
}
|
|
90
|
-
|
|
59
|
+
if(error.message.includes("reading 'init'")){
|
|
60
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
61
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
62
|
+
console.error(`\tdbcube run create:database`);
|
|
63
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
91
64
|
process.exit(1);
|
|
65
|
+
} else if(error.message.includes("reading 'getDatabase'")){
|
|
66
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
67
|
+
}else{
|
|
68
|
+
console.error('Error aqui:', error);
|
|
69
|
+
console.error('Error aqui:', error.message);
|
|
70
|
+
}
|
|
92
71
|
}
|
|
93
|
-
|
|
94
72
|
console.log('\n');
|
|
95
73
|
}
|
|
96
74
|
|
|
@@ -1,102 +1,29 @@
|
|
|
1
1
|
const { default: Schema } = require('@dbcube/schema-builder');
|
|
2
2
|
const ConfigFileUtils = require('./../../../utils/ConfigFileUtils');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
|
-
const { default: chalk } = require('chalk');
|
|
7
|
-
const ProgressIndicator = require('./../../../lib/ProgressIndicator');
|
|
8
3
|
|
|
9
4
|
async function main() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const progress = new ProgressIndicator();
|
|
14
|
-
progress.showHeader('Ejecutando fresh tables...', '🗑️');
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
-
await progress.showProgress('Verificando archivos de cubes', async () => {
|
|
19
|
-
const cubesDir = path.join(process.cwd(), 'dbcube', 'cubes');
|
|
20
|
-
|
|
21
|
-
if (!fs.existsSync(cubesDir)) {
|
|
22
|
-
throw new Error('❌ The cubes folder does not exist');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
26
|
-
|
|
27
|
-
if (cubeFiles.length === 0) {
|
|
28
|
-
throw new Error('❌ There are no cubes to execute');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return cubeFiles;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Cargar configuraciones de base de datos
|
|
35
|
-
const configuredDatabases = await progress.showProgress('Cargando configuraciones de base de datos', async () => {
|
|
36
|
-
return await ConfigFileUtils.getConfiguredDatabases();
|
|
37
|
-
});
|
|
5
|
+
try {
|
|
6
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
38
7
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log(` ${chalk.blue('├─')} Tablas encontradas: ${chalk.cyan(realTables.join(', '))}`);
|
|
59
|
-
console.log(` ${chalk.blue('├─')} Ejecutando fresh tables...`);
|
|
60
|
-
|
|
61
|
-
// Ejecutar el fresh real SIN animación para que se vean los mensajes del core
|
|
62
|
-
try {
|
|
63
|
-
const schema = new Schema(config.name);
|
|
64
|
-
const result = await schema.freshTables();
|
|
65
|
-
|
|
66
|
-
if (result === null) {
|
|
67
|
-
console.log(` ${chalk.red('├─')} ❌ Error: Base de datos ${config.name} no existe o no es accesible`);
|
|
68
|
-
totalTablesProcessed = 0;
|
|
69
|
-
} else {
|
|
70
|
-
console.log(` ${chalk.green('├─')} ✅ Fresh completado exitosamente`);
|
|
71
|
-
totalTablesProcessed += realTables.length;
|
|
72
|
-
}
|
|
73
|
-
} catch (schemaError) {
|
|
74
|
-
console.log(` ${chalk.red('├─')} ❌ Error durante fresh: ${schemaError.message}`);
|
|
75
|
-
totalTablesProcessed = 0;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
console.log(` ${chalk.blue('└─')} ${chalk.green('✓')} Procesamiento de ${config.name} completado`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Mostrar resumen
|
|
82
|
-
progress.showSummary('fresh', totalTablesProcessed, configuredDatabases.length);
|
|
83
|
-
|
|
84
|
-
} catch (error) {
|
|
85
|
-
progress.showError('Error durante el fresh', error);
|
|
86
|
-
|
|
87
|
-
if(error.message.includes("reading 'init'")){
|
|
88
|
-
console.error('\n💡 Soluciones sugeridas:');
|
|
89
|
-
console.error(` ${chalk.gray('├─')} Ejecutar: ${chalk.cyan('dbcube run database:create')}`);
|
|
90
|
-
console.error(` ${chalk.gray('└─')} Verificar archivo: ${chalk.cyan('dbcube.config.js')}`);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
} else if(error.message.includes("reading 'getDatabase'")){
|
|
93
|
-
console.error('💡 Se sugiere cambiar la configuración o crear la base de datos referenciada.');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
process.exit(1);
|
|
8
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
9
|
+
for (const config of configuredDatabases) {
|
|
10
|
+
const schema = new Schema(config.name);
|
|
11
|
+
await schema.freshTables();
|
|
12
|
+
}
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error.message.includes("reading 'init'")) {
|
|
15
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
16
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
17
|
+
console.error(`\tdbcube run create:database`);
|
|
18
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
} else if (error.message.includes("reading 'getDatabase'")) {
|
|
21
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
22
|
+
} else {
|
|
23
|
+
console.error('Error aqui:', error);
|
|
24
|
+
console.error('Error aqui:', error.message);
|
|
97
25
|
}
|
|
98
|
-
|
|
99
|
-
console.log('\n');
|
|
26
|
+
}
|
|
100
27
|
}
|
|
101
28
|
|
|
102
29
|
// Ejecutar el ejemplo
|
|
@@ -1,97 +1,29 @@
|
|
|
1
1
|
const { default: Schema } = require('@dbcube/schema-builder');
|
|
2
2
|
const ConfigFileUtils = require('./../../../utils/ConfigFileUtils');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
|
-
const { default: chalk } = require('chalk');
|
|
7
|
-
const ProgressIndicator = require('./../../../lib/ProgressIndicator');
|
|
8
3
|
|
|
9
4
|
async function main() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return cubeFiles;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Cargar configuraciones de base de datos
|
|
35
|
-
const configuredDatabases = await progress.showProgress('Cargando configuraciones de base de datos', async () => {
|
|
36
|
-
return await ConfigFileUtils.getConfiguredDatabases();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Obtener archivos .cube reales
|
|
40
|
-
const cubeFiles = await progress.showProgress('Analizando archivos .cube', async () => {
|
|
41
|
-
return FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
let totalTablesProcessed = 0;
|
|
45
|
-
|
|
46
|
-
// Procesar cada base de datos
|
|
47
|
-
for (const config of configuredDatabases) {
|
|
48
|
-
console.log(`\n${chalk.blue('┌─')} Procesando base de datos: ${chalk.bold(config.name)} ${chalk.gray(`(${config.type})`)}`);
|
|
49
|
-
|
|
50
|
-
// Obtener nombres reales de las tablas desde los archivos .cube
|
|
51
|
-
const realTables = progress.extractTableNamesFromCubes(cubeFiles);
|
|
52
|
-
|
|
53
|
-
if (realTables.length === 0) {
|
|
54
|
-
console.log(` ${chalk.yellow('└─')} No se encontraron tablas en los archivos .cube`);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log(` ${chalk.blue('├─')} Tablas encontradas: ${chalk.cyan(realTables.join(', '))}`);
|
|
59
|
-
console.log(` ${chalk.blue('├─')} Ejecutando refresh tables...`);
|
|
60
|
-
|
|
61
|
-
// Ejecutar el refresh real SIN animación para que se vean los mensajes del core
|
|
62
|
-
try {
|
|
63
|
-
const schema = new Schema(config.name);
|
|
64
|
-
await schema.refreshTables();
|
|
65
|
-
|
|
66
|
-
console.log(` ${chalk.green('├─')} ✅ Refresh completado exitosamente`);
|
|
67
|
-
totalTablesProcessed += realTables.length;
|
|
68
|
-
} catch (schemaError) {
|
|
69
|
-
console.log(` ${chalk.red('├─')} ❌ Error durante refresh: ${schemaError.message}`);
|
|
70
|
-
totalTablesProcessed = 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
console.log(` ${chalk.blue('└─')} ${chalk.green('✓')} Procesamiento de ${config.name} completado`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Mostrar resumen
|
|
77
|
-
progress.showSummary('refresh', totalTablesProcessed, configuredDatabases.length);
|
|
78
|
-
|
|
79
|
-
} catch (error) {
|
|
80
|
-
progress.showError('Error durante el refresh', error);
|
|
81
|
-
|
|
82
|
-
if(error.message.includes("reading 'init'")){
|
|
83
|
-
console.error('\n💡 Soluciones sugeridas:');
|
|
84
|
-
console.error(` ${chalk.gray('├─')} Ejecutar: ${chalk.cyan('dbcube run database:create')}`);
|
|
85
|
-
console.error(` ${chalk.gray('└─')} Verificar archivo: ${chalk.cyan('dbcube.config.js')}`);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
} else if(error.message.includes("reading 'getDatabase'")){
|
|
88
|
-
console.error('💡 Se sugiere cambiar la configuración o crear la base de datos referenciada.');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
process.exit(1);
|
|
5
|
+
console.clear();
|
|
6
|
+
try {
|
|
7
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
8
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
9
|
+
for (const config of configuredDatabases) {
|
|
10
|
+
const schema = new Schema(config.name);
|
|
11
|
+
await schema.refreshTables();
|
|
12
|
+
}
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error.message.includes("reading 'init'")) {
|
|
15
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
16
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
17
|
+
console.error(`\tdbcube run create:database`);
|
|
18
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
} else if (error.message.includes("reading 'getDatabase'")) {
|
|
21
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
22
|
+
} else {
|
|
23
|
+
console.error('Error aqui:', error);
|
|
24
|
+
console.error('Error aqui:', error.message);
|
|
92
25
|
}
|
|
93
|
-
|
|
94
|
-
console.log('\n');
|
|
26
|
+
}
|
|
95
27
|
}
|
|
96
28
|
|
|
97
29
|
// Ejecutar el ejemplo
|
|
@@ -4,93 +4,71 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
6
|
const { default: chalk } = require('chalk');
|
|
7
|
-
const
|
|
7
|
+
const { default: ora } = require('ora');
|
|
8
|
+
const { default: alwait } = require('alwait');
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
// Suprimir logs de dotenv
|
|
11
12
|
process.env.DOTENV_SILENT = 'true';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
console.clear();
|
|
15
|
+
console.log(`\n⚡ ${chalk.green("Ejecutando triggers...")}`);
|
|
16
16
|
try {
|
|
17
17
|
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!fs.existsSync(cubesDir)) {
|
|
22
|
-
throw new Error('❌ The cubes folder does not exist');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
26
|
-
|
|
27
|
-
if (cubeFiles.length === 0) {
|
|
28
|
-
throw new Error('❌ There are no cubes to execute');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return cubeFiles;
|
|
32
|
-
});
|
|
18
|
+
const spinner = ora('Preparando ejecución de triggers...').start();
|
|
19
|
+
await alwait(500);
|
|
20
|
+
const cubesDir = path.join(process.cwd(), 'dbcube', 'cubes');
|
|
33
21
|
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Obtener archivos .cube reales
|
|
40
|
-
const cubeFiles = await progress.showProgress('Analizando archivos .cube', async () => {
|
|
41
|
-
return FileUtils.getCubeFilesRecursively('dbcube', 'table.cube');
|
|
42
|
-
});
|
|
22
|
+
// Verificar si la carpeta existe
|
|
23
|
+
if (!fs.existsSync(cubesDir)) {
|
|
24
|
+
spinner.fail('Carpeta de cubes no encontrada');
|
|
25
|
+
throw new Error('❌ The cubes folder does not exist');
|
|
26
|
+
}
|
|
43
27
|
|
|
44
|
-
|
|
28
|
+
// Leer todos los archivos en la carpeta
|
|
29
|
+
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube')
|
|
45
30
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
if (cubeFiles.length === 0) {
|
|
32
|
+
spinner.fail('No hay cubes para ejecutar');
|
|
33
|
+
throw new Error('❌ There are no cubes to execute');
|
|
34
|
+
} else {
|
|
35
|
+
spinner.succeed('Cubes encontrados correctamente');
|
|
49
36
|
|
|
50
|
-
|
|
51
|
-
|
|
37
|
+
const loadingSpinner = ora('Cargando configuraciones de base de datos...').start();
|
|
38
|
+
let countTableCreated = 0;
|
|
39
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
40
|
+
loadingSpinner.succeed(`Configuraciones cargadas (${configuredDatabases.length} bases de datos)`);
|
|
52
41
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
43
|
+
for (const config of configuredDatabases) {
|
|
44
|
+
const triggerSpinner = ora(`Ejecutando triggers para: ${config.name} (${config.type})...`).start();
|
|
45
|
+
const schema = new Schema(config.name);
|
|
46
|
+
await schema.executeTriggers();
|
|
47
|
+
triggerSpinner.succeed(`Triggers ejecutados para: ${config.name}`);
|
|
48
|
+
countTableCreated++;
|
|
56
49
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const schema = new Schema(config.name);
|
|
64
|
-
await schema.executeTriggers();
|
|
65
|
-
|
|
66
|
-
console.log(` ${chalk.green('├─')} ✅ Triggers completados exitosamente`);
|
|
67
|
-
totalTriggersProcessed += realTriggers.length;
|
|
68
|
-
} catch (schemaError) {
|
|
69
|
-
console.log(` ${chalk.red('├─')} ❌ Error durante triggers: ${schemaError.message}`);
|
|
70
|
-
totalTriggersProcessed = 0;
|
|
50
|
+
|
|
51
|
+
if(countTableCreated==0) {
|
|
52
|
+
console.log(`\n⚠️ ${chalk.yellow('No hay triggers para ejecutar.')}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`\n🎉 ${chalk.green(`Triggers ejecutados exitosamente en ${countTableCreated} base(s) de datos!`)}`);
|
|
71
55
|
}
|
|
72
56
|
|
|
73
|
-
console.log(` ${chalk.blue('└─')} ${chalk.green('✓')} Procesamiento de ${config.name} completado`);
|
|
74
57
|
}
|
|
75
|
-
|
|
76
|
-
// Mostrar resumen
|
|
77
|
-
progress.showSummary('trigger', totalTriggersProcessed, configuredDatabases.length);
|
|
78
|
-
|
|
79
58
|
} catch (error) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
console.error(` ${chalk.gray('└─')} Verificar archivo: ${chalk.cyan('dbcube.config.js')}`);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
} else if(error.message.includes("reading 'getDatabase'")){
|
|
88
|
-
console.error('💡 Se sugiere cambiar la configuración o crear la base de datos referenciada.');
|
|
89
|
-
}
|
|
90
|
-
|
|
59
|
+
if(error.message.includes("reading 'init'")){
|
|
60
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
61
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
62
|
+
console.error(`\tdbcube run create:database`);
|
|
63
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
91
64
|
process.exit(1);
|
|
65
|
+
} else if(error.message.includes("reading 'getDatabase'")){
|
|
66
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
67
|
+
}else{
|
|
68
|
+
console.error('Error aqui:', error);
|
|
69
|
+
console.error('Error aqui:', error.message);
|
|
70
|
+
}
|
|
92
71
|
}
|
|
93
|
-
|
|
94
72
|
console.log('\n');
|
|
95
73
|
}
|
|
96
74
|
|
package/src/index.js
CHANGED
|
@@ -28,17 +28,17 @@ class ProgressIndicator {
|
|
|
28
28
|
const startTime = Date.now();
|
|
29
29
|
const maxDots = 50;
|
|
30
30
|
const operationText = this.getOperationText(operation);
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
// Formatear el nombre para que tenga un ancho fijo
|
|
33
33
|
const displayName = databaseName ? `${databaseName}.${tableName}` : tableName;
|
|
34
|
-
const truncatedName = displayName.length > 30 ?
|
|
35
|
-
displayName.substring(0, 27) + '...' :
|
|
34
|
+
const truncatedName = displayName.length > 30 ?
|
|
35
|
+
displayName.substring(0, 27) + '...' :
|
|
36
36
|
displayName.padEnd(30);
|
|
37
37
|
|
|
38
38
|
// Simular progreso con puntos
|
|
39
39
|
return new Promise((resolve) => {
|
|
40
|
-
process.stdout.write(
|
|
41
|
-
|
|
40
|
+
process.stdout.write(`${chalk.gray('├─')} ${truncatedName} `);
|
|
41
|
+
|
|
42
42
|
let dotCount = 0;
|
|
43
43
|
const interval = setInterval(() => {
|
|
44
44
|
if (dotCount < maxDots) {
|
|
@@ -64,19 +64,19 @@ class ProgressIndicator {
|
|
|
64
64
|
async showMultipleTablesProgress(tables, operation, databaseName, executor) {
|
|
65
65
|
const operationText = this.getOperationText(operation);
|
|
66
66
|
console.log(` ${chalk.blue('┌─')} ${operationText} en ${chalk.bold(databaseName)}:`);
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
for (let i = 0; i < tables.length; i++) {
|
|
69
69
|
const table = tables[i];
|
|
70
70
|
const isLast = i === tables.length - 1;
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
await this.showTableProgress(table, operation, '');
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
if (executor) {
|
|
75
75
|
await executor(table);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
console.log(
|
|
78
|
+
|
|
79
|
+
console.log(`${chalk.blue('└─')} ${chalk.green('Completado')}`);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
@@ -87,7 +87,7 @@ class ProgressIndicator {
|
|
|
87
87
|
async showProgress(message, executor) {
|
|
88
88
|
const spinner = ora(message).start();
|
|
89
89
|
const startTime = Date.now();
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
try {
|
|
92
92
|
const result = await executor();
|
|
93
93
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
@@ -108,13 +108,20 @@ class ProgressIndicator {
|
|
|
108
108
|
showSummary(operation, count, databases) {
|
|
109
109
|
const totalTime = this.startTime ? ((Date.now() - this.startTime) / 1000).toFixed(1) : '0.0';
|
|
110
110
|
const operationText = this.getOperationText(operation);
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
console.log(`\n${chalk.green('🎉')} ${chalk.bold('Resumen:')}`);
|
|
113
113
|
console.log(` ${chalk.gray('├─')} ${operationText}: ${chalk.cyan(count)} elementos`);
|
|
114
114
|
console.log(` ${chalk.gray('├─')} Bases de datos: ${chalk.cyan(databases)}`);
|
|
115
115
|
console.log(` ${chalk.gray('└─')} Tiempo total: ${chalk.cyan(totalTime + 's')}`);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Inicia el cronómetro
|
|
120
|
+
*/
|
|
121
|
+
startTimer() {
|
|
122
|
+
this.startTime = Date.now();
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
/**
|
|
119
126
|
* Muestra error con formato
|
|
120
127
|
* @param {string} message - Mensaje de error
|
|
@@ -148,32 +155,32 @@ class ProgressIndicator {
|
|
|
148
155
|
*/
|
|
149
156
|
extractTableNamesFromCubes(cubeFiles) {
|
|
150
157
|
const tableNames = [];
|
|
151
|
-
|
|
158
|
+
|
|
152
159
|
for (const filePath of cubeFiles) {
|
|
153
160
|
try {
|
|
154
161
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
155
|
-
|
|
162
|
+
|
|
156
163
|
// Patrón principal: @meta({ name: "nombre_tabla"; }) o @meta({ name: 'nombre_tabla'; })
|
|
157
164
|
const metaMatch = content.match(/@meta\s*\(\s*\{\s*name\s*:\s*["']([^"']+)["']\s*;?\s*[^}]*\}\s*\)/);
|
|
158
165
|
if (metaMatch) {
|
|
159
166
|
tableNames.push(metaMatch[1]);
|
|
160
167
|
continue;
|
|
161
168
|
}
|
|
162
|
-
|
|
169
|
+
|
|
163
170
|
// Patrón alternativo: @table("nombre_tabla") o @table('nombre_tabla')
|
|
164
171
|
const tableMatch = content.match(/@table\(\s*["']([^"']+)["']\s*\)/);
|
|
165
172
|
if (tableMatch) {
|
|
166
173
|
tableNames.push(tableMatch[1]);
|
|
167
174
|
continue;
|
|
168
175
|
}
|
|
169
|
-
|
|
176
|
+
|
|
170
177
|
// Patrón 3: table: "nombre_tabla" o table: 'nombre_tabla'
|
|
171
178
|
const tableMatch2 = content.match(/table\s*:\s*["']([^"']+)["']/);
|
|
172
179
|
if (tableMatch2) {
|
|
173
180
|
tableNames.push(tableMatch2[1]);
|
|
174
181
|
continue;
|
|
175
182
|
}
|
|
176
|
-
|
|
183
|
+
|
|
177
184
|
// Fallback: usar el nombre del archivo sin la extensión .cube
|
|
178
185
|
const fileName = path.basename(filePath, '.table.cube');
|
|
179
186
|
if (fileName && fileName !== 'table') {
|
|
@@ -183,7 +190,7 @@ class ProgressIndicator {
|
|
|
183
190
|
tableNames.push(cleanName);
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
|
|
193
|
+
|
|
187
194
|
} catch (error) {
|
|
188
195
|
// Si no se puede leer el archivo, usar el nombre del archivo
|
|
189
196
|
const fileName = path.basename(filePath, '.table.cube');
|
|
@@ -193,7 +200,7 @@ class ProgressIndicator {
|
|
|
193
200
|
}
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
|
-
|
|
203
|
+
|
|
197
204
|
return [...new Set(tableNames)]; // Eliminar duplicados
|
|
198
205
|
}
|
|
199
206
|
|
|
@@ -204,11 +211,11 @@ class ProgressIndicator {
|
|
|
204
211
|
*/
|
|
205
212
|
extractSeederNamesFromCubes(cubeFiles) {
|
|
206
213
|
const seederNames = [];
|
|
207
|
-
|
|
214
|
+
|
|
208
215
|
for (const filePath of cubeFiles) {
|
|
209
216
|
try {
|
|
210
217
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
211
|
-
|
|
218
|
+
|
|
212
219
|
// Buscar secciones de seeders en el archivo
|
|
213
220
|
const seederMatches = content.match(/@seeder\s*\(\s*["']([^"']+)["']\s*\)/g);
|
|
214
221
|
if (seederMatches) {
|
|
@@ -223,7 +230,7 @@ class ProgressIndicator {
|
|
|
223
230
|
seederNames.push(`${tableNames[0]}Seeder`);
|
|
224
231
|
}
|
|
225
232
|
}
|
|
226
|
-
|
|
233
|
+
|
|
227
234
|
} catch (error) {
|
|
228
235
|
// Fallback: usar nombre del archivo
|
|
229
236
|
const fileName = path.basename(filePath, '.table.cube');
|
|
@@ -233,7 +240,7 @@ class ProgressIndicator {
|
|
|
233
240
|
}
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
|
-
|
|
243
|
+
|
|
237
244
|
return seederNames;
|
|
238
245
|
}
|
|
239
246
|
|
|
@@ -244,11 +251,11 @@ class ProgressIndicator {
|
|
|
244
251
|
*/
|
|
245
252
|
extractTriggerNamesFromCubes(cubeFiles) {
|
|
246
253
|
const triggerNames = [];
|
|
247
|
-
|
|
254
|
+
|
|
248
255
|
for (const filePath of cubeFiles) {
|
|
249
256
|
try {
|
|
250
257
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
251
|
-
|
|
258
|
+
|
|
252
259
|
// Buscar triggers en el archivo
|
|
253
260
|
const triggerMatches = content.match(/@trigger\s*\(\s*["']([^"']+)["']\s*\)/g);
|
|
254
261
|
if (triggerMatches) {
|
|
@@ -264,7 +271,7 @@ class ProgressIndicator {
|
|
|
264
271
|
triggerNames.push(`before_insert_${tableName}`);
|
|
265
272
|
}
|
|
266
273
|
}
|
|
267
|
-
|
|
274
|
+
|
|
268
275
|
} catch (error) {
|
|
269
276
|
// Fallback: usar nombre del archivo
|
|
270
277
|
const fileName = path.basename(filePath, '.table.cube');
|
|
@@ -274,7 +281,7 @@ class ProgressIndicator {
|
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
|
-
|
|
284
|
+
|
|
278
285
|
return triggerNames;
|
|
279
286
|
}
|
|
280
287
|
|
|
@@ -287,6 +294,7 @@ class ProgressIndicator {
|
|
|
287
294
|
console.clear();
|
|
288
295
|
console.log(`\n${emoji} ${chalk.green.bold(title)}`);
|
|
289
296
|
console.log(chalk.gray('─'.repeat(50)));
|
|
297
|
+
this.startTime = Date.now(); // Iniciar cronómetro aquí
|
|
290
298
|
}
|
|
291
299
|
}
|
|
292
300
|
|
package/.lh/.lhignore
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# list file to not track by the local-history extension. comment line starts with a '#' character
|
|
2
|
-
# each line describe a regular expression pattern (search for 'Javascript regex')
|
|
3
|
-
# it will relate to the workspace directory root. for example:
|
|
4
|
-
# '.*\.txt' ignores any file with 'txt' extension
|
|
5
|
-
# '/test/.*' ignores all the files under the 'test' directory
|
|
6
|
-
# '.*/test/.*' ignores all the files under any 'test' directory (even under sub-folders)
|
package/.lh/package.json.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"sourceFile": "package.json",
|
|
3
|
-
"activeCommit": 0,
|
|
4
|
-
"commits": [
|
|
5
|
-
{
|
|
6
|
-
"activePatchIndex": 2,
|
|
7
|
-
"patches": [
|
|
8
|
-
{
|
|
9
|
-
"date": 1756705588331,
|
|
10
|
-
"content": "Index: \n===================================================================\n--- \n+++ \n"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"date": 1756705654448,
|
|
14
|
-
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -13,9 +13,8 @@\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\": \"\",\n \"dependencies\": {\n- \"@dbcube/schema-builder\": \"^1.0.0\",\n \"@inquirer/prompts\": \"^7.4.1\",\n \"alwait\": \"^1.0.0\",\n \"chalk\": \"^5.4.1\",\n \"dotenv\": \"^17.0.1\",\n"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"date": 1756706224795,
|
|
18
|
-
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -2,9 +2,8 @@\n \"name\": \"dbcube\",\n \"version\": \"1.0.1\",\n \"main\": \"index.js\",\n \"scripts\": {\n- \"start\": \"node example.js\",\n \"dbcube\": \"node src/index.js\"\n },\n \"bin\": {\n \"dbcube\": \"./src/index.js\"\n"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"date": 1756705588331,
|
|
22
|
-
"name": "Commit-0",
|
|
23
|
-
"content": "{\n \"name\": \"dbcube\",\n \"version\": \"1.0.0\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"start\": \"node example.js\",\n \"dbcube\": \"node src/index.js\"\n },\n \"bin\": {\n \"dbcube\": \"./src/index.js\"\n },\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\": \"\",\n \"dependencies\": {\n \"@inquirer/prompts\": \"^7.4.1\",\n \"alwait\": \"^1.0.0\",\n \"chalk\": \"^5.4.1\",\n \"dotenv\": \"^17.0.1\",\n \"fs-extra\": \"^11.3.0\",\n \"glob\": \"^11.0.1\",\n \"ora\": \"^8.2.0\"\n }\n}\n"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|